update
This commit is contained in:
14
cache/redis/cache.go
vendored
14
cache/redis/cache.go
vendored
@@ -5,6 +5,7 @@ package redis
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
@@ -15,19 +16,20 @@ import (
|
||||
// prefix: 键前缀
|
||||
// params: 键参数
|
||||
// 返回: 完整的缓存键
|
||||
func (c *RedisClient) BuildKey(prefix string, params ...interface{}) string {
|
||||
key := vars.CacheKeyPrefix + prefix
|
||||
func (c *RedisClient) BuildKey(prefix string, params ...any) string {
|
||||
var key strings.Builder
|
||||
key.WriteString(vars.CacheKeyPrefix + prefix)
|
||||
for _, param := range params {
|
||||
key += fmt.Sprintf(":%v", param)
|
||||
key.WriteString(fmt.Sprintf(":%v", param))
|
||||
}
|
||||
return key
|
||||
return key.String()
|
||||
}
|
||||
|
||||
// Get 获取缓存
|
||||
// key: 缓存键
|
||||
// result: 存储结果的指针
|
||||
// 返回: 错误信息
|
||||
func (c *RedisClient) Get(key string, result interface{}) error {
|
||||
func (c *RedisClient) Get(key string, result any) error {
|
||||
if c.Client == nil {
|
||||
return errcode.ErrRedis
|
||||
}
|
||||
@@ -45,7 +47,7 @@ func (c *RedisClient) Get(key string, result interface{}) error {
|
||||
// value: 缓存值
|
||||
// ttl: 过期时间
|
||||
// 返回: 错误信息
|
||||
func (c *RedisClient) Set(key string, value interface{}, ttl time.Duration) error {
|
||||
func (c *RedisClient) Set(key string, value any, ttl time.Duration) error {
|
||||
if c.Client == nil {
|
||||
return errcode.ErrRedis
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user