扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
缓存组件同时提供了gcache
的Redis
缓存适配实现。Redis
缓存在多节点保证缓存的数据一致性时非常有用,特别是Session
共享、数据库查询缓存等场景中。
成都创新互联公司是一家专注于网站建设、网站制作与策划设计,克东网站建设哪家好?成都创新互联公司做网站,专注于网站建设十余年,网设计领域的专业建站公司;建站业务涵盖:克东等地区。克东做网站价格咨询:18982081108
func ExampleCache_SetAdapter() {
var (
err error
ctx = gctx.New()
cache = gcache.New()
redisConfig = &gredis.Config{
Address: "127.0.0.1:6379",
Db: 9,
}
cacheKey = `key`
cacheValue = `value`
)
// Create redis client object.
redis, err := gredis.New(redisConfig)
if err != nil {
panic(err)
}
// Create redis cache adapter and set it to cache object.
cache.SetAdapter(gcache.NewAdapterRedis(redis))
// Set and Get using cache object.
err = cache.Set(ctx, cacheKey, cacheValue, time.Second)
if err != nil {
panic(err)
}
fmt.Println(cache.MustGet(ctx, cacheKey).String())
// Get using redis client.
fmt.Println(redis.MustDo(ctx, "GET", cacheKey).String())
// Output:
// value
// value
}
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流