From 119420932b1cc965da2682c25256c1702a14ebdf Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sat, 21 Dec 2024 18:03:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9redis=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=89=80=E6=9C=89=E9=94=AE=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- worker/redis.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/worker/redis.go b/worker/redis.go index 9e660fa..868d4ee 100644 --- a/worker/redis.go +++ b/worker/redis.go @@ -464,7 +464,8 @@ func GetRedisSetUnion(key1 string, key2 string) []string { type RedisInfo struct { Key string Value string - Expire time.Duration + Type string + Expire int // 过期时间, 单位: 秒 } // 获取所有的key和value,及其对应的过期时间 @@ -478,7 +479,7 @@ func GetAllRedisInfo() ([]RedisInfo, error) { var redisInfos []RedisInfo for _, key := range keys { //先查看key类型,再根据类型获取value - val, err := getKeyTypeAndData(key) + key_type, val, err := getKeyTypeAndData(key) if err != nil { fmt.Println("Error getting key: %v", err) return nil, err @@ -491,14 +492,15 @@ func GetAllRedisInfo() ([]RedisInfo, error) { redisInfo := RedisInfo{ Key: key, Value: val, - Expire: expire, + Type: key_type, + Expire: int(expire.Seconds()), } redisInfos = append(redisInfos, redisInfo) } return redisInfos, nil } -func getKeyTypeAndData(key string) (string, error) { +func getKeyTypeAndData(key string) (string, string, error) { ctx := context.Background() key_type := RedisClient.Type(ctx, key).Val() var val interface{} @@ -519,5 +521,5 @@ func getKeyTypeAndData(key string) (string, error) { default: val = "unknown type" } - return fmt.Sprintf("%v", val), err + return key_type, fmt.Sprintf("%v", val), err }