Merge branch 'refs/heads/feat-conf-redis'

This commit is contained in:
junleea 2024-12-21 18:03:54 +08:00
commit 536b9eb29a
1 changed files with 7 additions and 5 deletions

View File

@ -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
}