From a85ebc0203293def78700f8eef99c957c620e665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 9 Oct 2024 18:18:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96key?= =?UTF-8?q?=E7=9A=84=E6=9C=89=E6=95=88=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 4 ++++ wrapper.go | 34 ++++++++++++++++++++++------------ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 9e92595..4348786 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module git.zhangdeman.cn/zhangdeman/redis go 1.22.4 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/wrapper v0.0.0-20240924063449-ef80c6cb79d1 github.com/pkg/errors v0.9.1 @@ -12,7 +13,6 @@ 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/op_type v0.0.0-20240122104027-4928421213c0 // indirect git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd // indirect diff --git a/go.sum b/go.sum index 1a44b7b..cd0a2df 100644 --- a/go.sum +++ b/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-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-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/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U= git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 h1:gUDlQMuJ4xNfP2Abl1Msmpa3fASLWYkNlqDFF/6GN0Y= diff --git a/wrapper.go b/wrapper.go index ac6509e..8fa3ce4 100644 --- a/wrapper.go +++ b/wrapper.go @@ -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, " ")) }