fix(redis): 修复缓存设置和清除逻辑的问题
Build docker and publish / build (20.15.1) (push) Successful in 7m20s

修复Redis缓存设置未设置TTL的问题,使用节点拉取间隔加60秒作为TTL
修复ClearServerAllCache中重复添加keys的问题
修复ClearServerCache中未使用cursor参数的问题
优化ClearServerAllCache以支持清除多种前缀的缓存
This commit is contained in:
2025-11-23 23:39:30 -08:00
parent 58107ed76f
commit 4ad384b01a
4 changed files with 57 additions and 50 deletions
@@ -4,6 +4,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"time"
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/model/node"
@@ -90,7 +91,8 @@ func (l *GetServerConfigLogic) GetServerConfig(req *types.GetServerConfigRequest
}
etag := tool.GenerateETag(c)
l.ctx.Header("ETag", etag)
if err = l.svcCtx.Redis.Set(l.ctx, cacheKey, c, -1).Err(); err != nil {
ttl := time.Second * time.Duration(l.svcCtx.Config.Node.NodePullInterval+60)
if err = l.svcCtx.Redis.Set(l.ctx, cacheKey, c, ttl).Err(); err != nil {
l.Errorw("[GetServerConfig] redis set error", logger.Field("error", err.Error()))
}
// Check If-None-Match header
@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"strings"
"time"
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/model/node"
@@ -121,10 +122,11 @@ func (l *GetServerUserListLogic) GetServerUserList(req *types.GetServerUserListR
val, _ := json.Marshal(resp)
etag := tool.GenerateETag(val)
l.ctx.Header("ETag", etag)
err = l.svcCtx.Redis.Set(l.ctx, cacheKey, string(val), -1).Err()
if err != nil {
l.Errorw("[ServerUserListCacheKey] redis set error", logger.Field("error", err.Error()))
}
ttl := time.Second * time.Duration(l.svcCtx.Config.Node.NodePullInterval+60)
err = l.svcCtx.Redis.Set(l.ctx, cacheKey, string(val), ttl).Err()
if err != nil {
l.Errorw("[ServerUserListCacheKey] redis set error", logger.Field("error", err.Error()))
}
// Check If-None-Match header
if match := l.ctx.GetHeader("If-None-Match"); match == etag {
return nil, xerr.StatusNotModified