feat: SetEx value参数 string -> any

This commit is contained in:
2025-10-18 11:24:16 +08:00
parent 5823bb2542
commit adc90ef927

View File

@ -9,10 +9,11 @@ package redis
import ( import (
"context" "context"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/redis/define"
"strings" "strings"
"time" "time"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/redis/define"
) )
var ( var (
@ -20,55 +21,31 @@ var (
) )
// wrapper 常用命令的包装 // wrapper 常用命令的包装
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:16 2024/6/19
type wrapper struct { type wrapper struct {
} }
// Exist 缓存Key是否存在 // Exist 缓存Key是否存在
//
// Author : go_developer@163.com<白茶清欢>
//
// 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, consts.RedisCommandExists, key) return Client.Exec(ctx, instanceFlag, consts.RedisCommandExists, key)
} }
// TTL ... // 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 { func (w *wrapper) TTL(ctx context.Context, instanceFlag string, key string) *define.RedisResult {
return Client.Exec(ctx, instanceFlag, consts.RedisCommandTTL, key) return Client.Exec(ctx, instanceFlag, consts.RedisCommandTTL, key)
} }
// Get Get命令 // Get Get命令
//
// Author : go_developer@163.com<白茶清欢>
//
// 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, consts.RedisCommandGet, key) return Client.Exec(ctx, instanceFlag, consts.RedisCommandGet, key)
} }
// Del 删除命令 // Del 删除命令
//
// Author : go_developer@163.com<白茶清欢>
//
// 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, consts.RedisCommandDel, strings.Join(keyList, " ")) return Client.Exec(ctx, instanceFlag, consts.RedisCommandDel, strings.Join(keyList, " "))
} }
// SetEx 设置数据并且带有效期, 有效期单位 : s // SetEx 设置数据并且带有效期, 有效期单位 : s
// func (w *wrapper) SetEx(ctx context.Context, instanceFlag string, key string, value any, ttl int64, withLock bool) *define.RedisResult {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:22 2024/6/19
func (w *wrapper) SetEx(ctx context.Context, instanceFlag string, key string, value string, ttl int64, withLock bool) *define.RedisResult {
now := time.Now().Unix() now := time.Now().Unix()
if ttl > now { if ttl > now {
// 传入过期时间大于当前时间, 说明是指定具体时间过期, 做一下处理 // 传入过期时间大于当前时间, 说明是指定具体时间过期, 做一下处理
@ -81,64 +58,36 @@ func (w *wrapper) SetEx(ctx context.Context, instanceFlag string, key string, va
} }
// LPop ... // LPop ...
//
// Author : go_developer@163.com<白茶清欢>
//
// 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, consts.RedisCommandLpop, key) return Client.Exec(ctx, instanceFlag, consts.RedisCommandLpop, key)
} }
// RPop ... // RPop ...
//
// Author : go_developer@163.com<白茶清欢>
//
// 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, consts.RedisCommandRpop, key) return Client.Exec(ctx, instanceFlag, consts.RedisCommandRpop, key)
} }
// LPush ... // LPush ...
//
// Author : go_developer@163.com<白茶清欢>
//
// 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, consts.RedisCommandLpush, key, value) return Client.Exec(ctx, instanceFlag, consts.RedisCommandLpush, key, value)
} }
// RPush ... // RPush ...
//
// Author : go_developer@163.com<白茶清欢>
//
// 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, consts.RedisCommandRpush, key, value) return Client.Exec(ctx, instanceFlag, consts.RedisCommandRpush, key, value)
} }
// HGet ... // HGet ...
//
// Author : go_developer@163.com<白茶清欢>
//
// 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, consts.RedisCommandHget, key, field) return Client.Exec(ctx, instanceFlag, consts.RedisCommandHget, key, field)
} }
// HSet ... // HSet ...
//
// Author : go_developer@163.com<白茶清欢>
//
// 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, consts.RedisCommandHset, key, field, value) return Client.Exec(ctx, instanceFlag, consts.RedisCommandHset, key, field, value)
} }
// HDel ... // HDel ...
//
// Author : go_developer@163.com<白茶清欢>
//
// 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, consts.RedisCommandHdel, key, strings.Join(fieldList, " ")) return Client.Exec(ctx, instanceFlag, consts.RedisCommandHdel, key, strings.Join(fieldList, " "))
} }