feat: 增加空缓存实现的支持
This commit is contained in:
12
redis.go
12
redis.go
@@ -9,21 +9,19 @@ package cache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
cacheAbstract "git.zhangdeman.cn/zhangdeman/cache/abstract"
|
||||
"git.zhangdeman.cn/zhangdeman/redis"
|
||||
"git.zhangdeman.cn/zhangdeman/wrapper/op_string"
|
||||
redisClient "github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
var (
|
||||
RedisClient = &Redis{}
|
||||
RedisClient cacheAbstract.ICache = &Redis{}
|
||||
)
|
||||
|
||||
// Redis 基于redis缓存
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:19 2023/3/21
|
||||
type Redis struct {
|
||||
}
|
||||
|
||||
@@ -33,6 +31,10 @@ func (r *Redis) Exist(ctx context.Context, instanceFlag string, key string) (boo
|
||||
ctx = context.Background()
|
||||
}
|
||||
res := redis.Wrapper.Exist(ctx, instanceFlag, key)
|
||||
if nil != res.Err && errors.Is(res.Err, redisClient.Nil) {
|
||||
// 未查询到数据, 也是数据不存在
|
||||
return false, nil
|
||||
}
|
||||
return res.Result == "1", res.Err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user