缓存支持读取缓存key的剩余有效时间

This commit is contained in:
2024-10-09 18:30:12 +08:00
parent 225a1ae9b2
commit 9088f515d3
5 changed files with 52 additions and 6 deletions

View File

@ -11,6 +11,7 @@ import (
"context"
cacheAbstract "git.zhangdeman.cn/zhangdeman/cache/abstract"
"git.zhangdeman.cn/zhangdeman/redis"
"git.zhangdeman.cn/zhangdeman/wrapper"
)
var (
@ -38,6 +39,19 @@ func (r *Redis) Exist(ctx context.Context, instanceFlag string, key string) (boo
return res.Result == "1", res.Err
}
// TTL 获取key的剩余有效期
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:11 2024/10/9
func (r *Redis) TTL(ctx context.Context, instanceFlag string, key string) (int64, error) {
if nil == ctx {
ctx = context.Background()
}
res := redis.Wrapper.TTL(ctx, instanceFlag, key)
return wrapper.String(res.Result).ToInt64().Value, res.Err
}
// Set 设置缓存
//
// Author : go_developer@163.com<白茶清欢>