增加获取key的有效期

This commit is contained in:
2024-10-09 18:18:49 +08:00
parent ec5f5f0161
commit a85ebc0203
3 changed files with 27 additions and 13 deletions

View File

@ -9,6 +9,7 @@ package redis
import (
"context"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/redis/define"
"strings"
"time"
@ -32,7 +33,16 @@ type wrapper struct {
//
// Date : 12:31 2024/6/21
func (w *wrapper) Exist(ctx context.Context, instanceFlag string, key string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, "EXISTS", key)
return Client.Exec(ctx, instanceFlag, consts.RedisCommandExists, key)
}
// TTL ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:14 2024/10/9
func (w *wrapper) TTL(ctx context.Context, instanceFlag string, key string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, consts.RedisCommandTTL, key)
}
// Get Get命令
@ -41,7 +51,7 @@ func (w *wrapper) Exist(ctx context.Context, instanceFlag string, key string) *d
//
// Date : 16:17 2024/6/19
func (w *wrapper) Get(ctx context.Context, instanceFlag string, key string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, "GET", key)
return Client.Exec(ctx, instanceFlag, consts.RedisCommandGet, key)
}
// Del 删除命令
@ -50,7 +60,7 @@ func (w *wrapper) Get(ctx context.Context, instanceFlag string, key string) *def
//
// Date : 16:19 2024/6/19
func (w *wrapper) Del(ctx context.Context, instanceFlag string, keyList ...string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, "DEL", strings.Join(keyList, " "))
return Client.Exec(ctx, instanceFlag, consts.RedisCommandDel, strings.Join(keyList, " "))
}
// SetEx 设置数据并且带有效期, 有效期单位 : s
@ -65,9 +75,9 @@ func (w *wrapper) SetEx(ctx context.Context, instanceFlag string, key string, va
ttl = ttl - now
}
if withLock {
return Client.Exec(ctx, instanceFlag, "SET", key, value, "EX", ttl, "NX")
return Client.Exec(ctx, instanceFlag, consts.RedisCommandSet, key, value, "EX", ttl, "NX")
}
return Client.Exec(ctx, instanceFlag, "SET", key, value, "EX", ttl)
return Client.Exec(ctx, instanceFlag, consts.RedisCommandSet, key, value, "EX", ttl)
}
// LPop ...
@ -76,7 +86,7 @@ func (w *wrapper) SetEx(ctx context.Context, instanceFlag string, key string, va
//
// Date : 16:29 2024/6/19
func (w *wrapper) LPop(ctx context.Context, instanceFlag string, key string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, "LPOP", key)
return Client.Exec(ctx, instanceFlag, consts.RedisCommandLpop, key)
}
// RPop ...
@ -85,7 +95,7 @@ func (w *wrapper) LPop(ctx context.Context, instanceFlag string, key string) *de
//
// Date : 16:30 2024/6/19
func (w *wrapper) RPop(ctx context.Context, instanceFlag string, key string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, "RPOP", key)
return Client.Exec(ctx, instanceFlag, consts.RedisCommandRpop, key)
}
// LPush ...
@ -94,7 +104,7 @@ func (w *wrapper) RPop(ctx context.Context, instanceFlag string, key string) *de
//
// Date : 16:31 2024/6/19
func (w *wrapper) LPush(ctx context.Context, instanceFlag string, key string, value string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, "LPUSH", key, value)
return Client.Exec(ctx, instanceFlag, consts.RedisCommandLpush, key, value)
}
// RPush ...
@ -103,7 +113,7 @@ func (w *wrapper) LPush(ctx context.Context, instanceFlag string, key string, va
//
// Date : 16:31 2024/6/19
func (w *wrapper) RPush(ctx context.Context, instanceFlag string, key string, value string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, "RPUSH", key, value)
return Client.Exec(ctx, instanceFlag, consts.RedisCommandRpush, key, value)
}
// HGet ...
@ -112,7 +122,7 @@ func (w *wrapper) RPush(ctx context.Context, instanceFlag string, key string, va
//
// Date : 16:33 2024/6/19
func (w *wrapper) HGet(ctx context.Context, instanceFlag string, key string, field string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, "HGET", key, field)
return Client.Exec(ctx, instanceFlag, consts.RedisCommandHget, key, field)
}
// HSet ...
@ -121,7 +131,7 @@ func (w *wrapper) HGet(ctx context.Context, instanceFlag string, key string, fie
//
// Date : 16:33 2024/6/19
func (w *wrapper) HSet(ctx context.Context, instanceFlag string, key string, field string, value string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, "HSET", key, field, value)
return Client.Exec(ctx, instanceFlag, consts.RedisCommandHset, key, field, value)
}
// HDel ...
@ -130,5 +140,5 @@ func (w *wrapper) HSet(ctx context.Context, instanceFlag string, key string, fie
//
// Date : 16:37 2024/6/19
func (w *wrapper) HDel(ctx context.Context, instanceFlag string, key string, fieldList ...string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, "HSET", key, strings.Join(fieldList, " "))
return Client.Exec(ctx, instanceFlag, consts.RedisCommandHdel, key, strings.Join(fieldList, " "))
}