增加获取key的有效期
This commit is contained in:
parent
ec5f5f0161
commit
a85ebc0203
2
go.mod
2
go.mod
@ -3,6 +3,7 @@ module git.zhangdeman.cn/zhangdeman/redis
|
|||||||
go 1.22.4
|
go 1.22.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241009101709-d8400fb206b4
|
||||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e
|
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e
|
||||||
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20240924063449-ef80c6cb79d1
|
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20240924063449-ef80c6cb79d1
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
@ -12,7 +13,6 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241008084126-0b1c661317ee // indirect
|
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 // indirect
|
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 // indirect
|
||||||
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 // indirect
|
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 // indirect
|
||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd // indirect
|
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd // indirect
|
||||||
|
4
go.sum
4
go.sum
@ -4,6 +4,10 @@ git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240924065029-c865046cd9e7 h1:tyCPCM
|
|||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240924065029-c865046cd9e7/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240924065029-c865046cd9e7/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241008084126-0b1c661317ee h1:4nuaCr5GQcx4z9/xWeEnjmLVV6J0j+QT68+AUKI9dFc=
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241008084126-0b1c661317ee h1:4nuaCr5GQcx4z9/xWeEnjmLVV6J0j+QT68+AUKI9dFc=
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241008084126-0b1c661317ee/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241008084126-0b1c661317ee/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||||
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241009101340-1d415ef93cac h1:0V9ubWn7VLmefcPuuUfmmioNhdWQ9FeTXpwGCwbb3hE=
|
||||||
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241009101340-1d415ef93cac/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||||
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241009101709-d8400fb206b4 h1:GUWgrIR7Gw1BIPzU6qUQgnB+7ZCE9nIwudAQTk7cyoU=
|
||||||
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241009101709-d8400fb206b4/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 h1:I/wOsRpCSRkU9vo1u703slQsmK0wnNeZzsWQOGtIAG0=
|
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 h1:I/wOsRpCSRkU9vo1u703slQsmK0wnNeZzsWQOGtIAG0=
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
|
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
|
||||||
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 h1:gUDlQMuJ4xNfP2Abl1Msmpa3fASLWYkNlqDFF/6GN0Y=
|
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 h1:gUDlQMuJ4xNfP2Abl1Msmpa3fASLWYkNlqDFF/6GN0Y=
|
||||||
|
34
wrapper.go
34
wrapper.go
@ -9,6 +9,7 @@ package redis
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"git.zhangdeman.cn/zhangdeman/consts"
|
||||||
"git.zhangdeman.cn/zhangdeman/redis/define"
|
"git.zhangdeman.cn/zhangdeman/redis/define"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -32,7 +33,16 @@ type wrapper struct {
|
|||||||
//
|
//
|
||||||
// Date : 12:31 2024/6/21
|
// Date : 12:31 2024/6/21
|
||||||
func (w *wrapper) Exist(ctx context.Context, instanceFlag string, key string) *define.RedisResult {
|
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命令
|
// Get Get命令
|
||||||
@ -41,7 +51,7 @@ func (w *wrapper) Exist(ctx context.Context, instanceFlag string, key string) *d
|
|||||||
//
|
//
|
||||||
// Date : 16:17 2024/6/19
|
// Date : 16:17 2024/6/19
|
||||||
func (w *wrapper) Get(ctx context.Context, instanceFlag string, key string) *define.RedisResult {
|
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 删除命令
|
// Del 删除命令
|
||||||
@ -50,7 +60,7 @@ func (w *wrapper) Get(ctx context.Context, instanceFlag string, key string) *def
|
|||||||
//
|
//
|
||||||
// Date : 16:19 2024/6/19
|
// Date : 16:19 2024/6/19
|
||||||
func (w *wrapper) Del(ctx context.Context, instanceFlag string, keyList ...string) *define.RedisResult {
|
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
|
// SetEx 设置数据并且带有效期, 有效期单位 : s
|
||||||
@ -65,9 +75,9 @@ func (w *wrapper) SetEx(ctx context.Context, instanceFlag string, key string, va
|
|||||||
ttl = ttl - now
|
ttl = ttl - now
|
||||||
}
|
}
|
||||||
if withLock {
|
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 ...
|
// LPop ...
|
||||||
@ -76,7 +86,7 @@ func (w *wrapper) SetEx(ctx context.Context, instanceFlag string, key string, va
|
|||||||
//
|
//
|
||||||
// Date : 16:29 2024/6/19
|
// Date : 16:29 2024/6/19
|
||||||
func (w *wrapper) LPop(ctx context.Context, instanceFlag string, key string) *define.RedisResult {
|
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 ...
|
// RPop ...
|
||||||
@ -85,7 +95,7 @@ func (w *wrapper) LPop(ctx context.Context, instanceFlag string, key string) *de
|
|||||||
//
|
//
|
||||||
// Date : 16:30 2024/6/19
|
// Date : 16:30 2024/6/19
|
||||||
func (w *wrapper) RPop(ctx context.Context, instanceFlag string, key string) *define.RedisResult {
|
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 ...
|
// LPush ...
|
||||||
@ -94,7 +104,7 @@ func (w *wrapper) RPop(ctx context.Context, instanceFlag string, key string) *de
|
|||||||
//
|
//
|
||||||
// Date : 16:31 2024/6/19
|
// Date : 16:31 2024/6/19
|
||||||
func (w *wrapper) LPush(ctx context.Context, instanceFlag string, key string, value string) *define.RedisResult {
|
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 ...
|
// RPush ...
|
||||||
@ -103,7 +113,7 @@ func (w *wrapper) LPush(ctx context.Context, instanceFlag string, key string, va
|
|||||||
//
|
//
|
||||||
// Date : 16:31 2024/6/19
|
// Date : 16:31 2024/6/19
|
||||||
func (w *wrapper) RPush(ctx context.Context, instanceFlag string, key string, value string) *define.RedisResult {
|
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 ...
|
// HGet ...
|
||||||
@ -112,7 +122,7 @@ func (w *wrapper) RPush(ctx context.Context, instanceFlag string, key string, va
|
|||||||
//
|
//
|
||||||
// Date : 16:33 2024/6/19
|
// Date : 16:33 2024/6/19
|
||||||
func (w *wrapper) HGet(ctx context.Context, instanceFlag string, key string, field string) *define.RedisResult {
|
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 ...
|
// HSet ...
|
||||||
@ -121,7 +131,7 @@ func (w *wrapper) HGet(ctx context.Context, instanceFlag string, key string, fie
|
|||||||
//
|
//
|
||||||
// Date : 16:33 2024/6/19
|
// Date : 16:33 2024/6/19
|
||||||
func (w *wrapper) HSet(ctx context.Context, instanceFlag string, key string, field string, value string) *define.RedisResult {
|
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 ...
|
// HDel ...
|
||||||
@ -130,5 +140,5 @@ func (w *wrapper) HSet(ctx context.Context, instanceFlag string, key string, fie
|
|||||||
//
|
//
|
||||||
// Date : 16:37 2024/6/19
|
// Date : 16:37 2024/6/19
|
||||||
func (w *wrapper) HDel(ctx context.Context, instanceFlag string, key string, fieldList ...string) *define.RedisResult {
|
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, " "))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user