feat: upgrade cache
This commit is contained in:
32
redis.go
32
redis.go
@ -28,10 +28,6 @@ type Redis struct {
|
||||
}
|
||||
|
||||
// Exist 缓存是否存在
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:02 2024/6/21
|
||||
func (r *Redis) Exist(ctx context.Context, instanceFlag string, key string) (bool, error) {
|
||||
if nil == ctx {
|
||||
ctx = context.Background()
|
||||
@ -41,10 +37,6 @@ func (r *Redis) Exist(ctx context.Context, instanceFlag string, key string) (boo
|
||||
}
|
||||
|
||||
// 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()
|
||||
@ -58,11 +50,7 @@ func (r *Redis) TTL(ctx context.Context, instanceFlag string, key string) (int64
|
||||
}
|
||||
|
||||
// Set 设置缓存
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 12:42 2023/3/25
|
||||
func (r *Redis) Set(ctx context.Context, instanceFlag string, key string, value string, ttl int64) error {
|
||||
func (r *Redis) Set(ctx context.Context, instanceFlag string, key string, value any, ttl int64) error {
|
||||
if nil == ctx {
|
||||
ctx = context.Background()
|
||||
}
|
||||
@ -70,11 +58,7 @@ func (r *Redis) Set(ctx context.Context, instanceFlag string, key string, value
|
||||
}
|
||||
|
||||
// Get 获取redis中的原始数据
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:52 2023/4/26
|
||||
func (r *Redis) Get(ctx context.Context, instanceFlag string, key string) (string, error) {
|
||||
func (r *Redis) Get(ctx context.Context, instanceFlag string, key string) (any, error) {
|
||||
if nil == ctx {
|
||||
ctx = context.Background()
|
||||
}
|
||||
@ -83,10 +67,6 @@ func (r *Redis) Get(ctx context.Context, instanceFlag string, key string) (strin
|
||||
}
|
||||
|
||||
// Delete 删除缓存
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 12:41 2023/3/25
|
||||
func (r *Redis) Delete(ctx context.Context, instanceFlag string, key string) error {
|
||||
if nil == ctx {
|
||||
ctx = context.Background()
|
||||
@ -95,13 +75,9 @@ func (r *Redis) Delete(ctx context.Context, instanceFlag string, key string) err
|
||||
}
|
||||
|
||||
// GetWithParse ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 12:26 2024/6/21
|
||||
func (r *Redis) GetWithParse(ctx context.Context, cacheInstanceFlag string, key string, parseFunc cacheAbstract.ResultParseFunc) (string, error) {
|
||||
func (r *Redis) GetWithParse(ctx context.Context, cacheInstanceFlag string, key string, parseFunc cacheAbstract.ResultParseFunc) (any, error) {
|
||||
var (
|
||||
res string
|
||||
res any
|
||||
err error
|
||||
)
|
||||
if res, err = r.Get(ctx, cacheInstanceFlag, key); nil != err {
|
||||
|
Reference in New Issue
Block a user