feat: 增加空缓存实现的支持

This commit is contained in:
2026-01-05 09:54:02 +08:00
parent 1fcb129079
commit 1fb1215a9c
6 changed files with 66 additions and 18 deletions

View File

@@ -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
}