2 Star 1 Fork 3

NilOrganization / go-opentaobao

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
redis.go 630 Bytes
一键复制 编辑 原始数据 按行查看 历史
Keng 提交于 2020-09-26 19:36 . update go-redis v8
package opentaobao
import (
"context"
"log"
"time"
"github.com/go-redis/redis/v8"
)
// SetRedis 设置RedisCache
func SetRedis(redisClient *redis.Client) {
GetCache = func(cacheKey string) []byte {
bytes, err := redisClient.Get(context.Background(), cacheKey).Bytes()
if err == redis.Nil {
return nil
} else if err != nil {
log.Println(err)
return nil
}
return bytes
}
SetCache = func(key string, value []byte, expiration time.Duration) bool {
err := redisClient.SetNX(context.Background(), key, value, expiration).Err()
if err != nil {
log.Println(err)
return false
}
return true
}
}
Go
1
https://gitee.com/nilorg/go-opentaobao.git
git@gitee.com:nilorg/go-opentaobao.git
nilorg
go-opentaobao
go-opentaobao
master

搜索帮助