ai update.

This commit is contained in:
2025-10-03 19:55:20 +08:00
parent 0401a39a94
commit 464617626b
15 changed files with 374 additions and 378 deletions

30
cache/redis/cache.go vendored
View File

@@ -1,3 +1,5 @@
// Package redis 提供Redis缓存操作功能
// 包括缓存设置、获取、删除等基本操作
package redis
import (
@@ -6,19 +8,15 @@ import (
"time"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/vars"
)
const (
// 缓存键前缀
CacheKeyPrefix = "bsm:"
// 缓存过期时间
DefaultTTL = 30 * time.Minute // 30分钟
)
// buildKey 构建缓存键
// BuildKey 构建缓存键
// prefix: 键前缀
// params: 键参数
// 返回: 完整的缓存键
func (c *RedisClient) BuildKey(prefix string, params ...interface{}) string {
key := CacheKeyPrefix + prefix
key := vars.CacheKeyPrefix + prefix
for _, param := range params {
key += fmt.Sprintf(":%v", param)
}
@@ -26,6 +24,9 @@ func (c *RedisClient) BuildKey(prefix string, params ...interface{}) string {
}
// Get 获取缓存
// key: 缓存键
// result: 存储结果的指针
// 返回: 错误信息
func (c *RedisClient) Get(key string, result interface{}) error {
if c.Client == nil {
return errcode.ErrRedis
@@ -40,6 +41,10 @@ func (c *RedisClient) Get(key string, result interface{}) error {
}
// Set 设置缓存
// key: 缓存键
// value: 缓存值
// ttl: 过期时间
// 返回: 错误信息
func (c *RedisClient) Set(key string, value interface{}, ttl time.Duration) error {
if c.Client == nil {
return errcode.ErrRedis
@@ -54,6 +59,8 @@ func (c *RedisClient) Set(key string, value interface{}, ttl time.Duration) erro
}
// Delete 删除缓存
// key: 缓存键
// 返回: 错误信息
func (c *RedisClient) Delete(key string) error {
if c.Client == nil {
return errcode.ErrRedis
@@ -63,12 +70,13 @@ func (c *RedisClient) Delete(key string) error {
}
// ClearAllCache 清除所有缓存
// 返回: 错误信息
func (c *RedisClient) ClearAllCache() error {
if c.Client == nil {
return errcode.ErrRedis
}
pattern := CacheKeyPrefix + "*"
pattern := vars.CacheKeyPrefix + "*"
keys, err := c.Client.Keys(c.Ctx, pattern).Result()
if err != nil {
return errcode.NewError(500, err.Error())