修复(#1): 服务器用户列表缓存按 protocol 隔离 + 兜底不写缓存

服务器用户列表缓存跨协议污染修复(HIF-1 / 详见 PR #5 四件套):

1. 缓存 key 加 protocol 维度(`server:user:{server_id}:{protocol}`),对齐 ServerConfig 已有约定
2. 显式枚举协议清除用户列表缓存(AllProtocols + ServerUserListCacheKeysForServer),不用 SCAN
3. 三个兜底分支不写缓存 + Errorw 日志(带 server_id + protocol 字段)
4. hysteria2 → hysteria 兼容归一化 + 6 个新单测

Closes HIF-1
This commit is contained in:
2026-06-03 05:37:03 -07:00
committed by GitHub
parent 8ff992e74c
commit 19d28a8f89
6 changed files with 220 additions and 14 deletions
@@ -3,7 +3,6 @@ package traffic
import (
"context"
"encoding/json"
"fmt"
"strings"
"time"
@@ -140,8 +139,8 @@ func (l *TrafficStatisticsLogic) ProcessTask(ctx context.Context, task *asynq.Ta
logger.Field("error", delErr.Error()),
)
}
cacheKey := fmt.Sprintf("%s%d", node.ServerUserListCacheKey, payload.ServerId)
if delErr := l.svc.Redis.Del(ctx, cacheKey).Err(); delErr != nil {
cacheKeys := node.ServerUserListCacheKeysForServer(payload.ServerId)
if delErr := l.svc.Redis.Del(ctx, cacheKeys...).Err(); delErr != nil {
logger.WithContext(ctx).Error("[TrafficStatistics] Clear server user cache failed",
logger.Field("serverId", payload.ServerId),
logger.Field("error", delErr.Error()),