修复Redis缓存设置未设置TTL的问题,使用节点拉取间隔加60秒作为TTL 修复ClearServerAllCache中重复添加keys的问题 修复ClearServerCache中未使用cursor参数的问题 优化ClearServerAllCache以支持清除多种前缀的缓存
This commit is contained in:
@@ -130,7 +130,7 @@ func (m *customServerModel) ClearNodeCache(ctx context.Context, params *FilterNo
|
||||
return err
|
||||
}
|
||||
if len(keys) > 0 {
|
||||
cacheKeys = append(keys, keys...)
|
||||
cacheKeys = append(cacheKeys, keys...)
|
||||
}
|
||||
cursor = newCursor
|
||||
if cursor == 0 {
|
||||
@@ -152,11 +152,11 @@ func (m *customServerModel) ClearServerCache(ctx context.Context, serverId int64
|
||||
var cacheKeys []string
|
||||
cacheKeys = append(cacheKeys, fmt.Sprintf("%s%d", ServerUserListCacheKey, serverId))
|
||||
var cursor uint64
|
||||
for {
|
||||
keys, newCursor, err := m.Cache.Scan(ctx, 0, fmt.Sprintf("%s%d*", ServerConfigCacheKey, serverId), 100).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for {
|
||||
keys, newCursor, err := m.Cache.Scan(ctx, cursor, fmt.Sprintf("%s%d*", ServerConfigCacheKey, serverId), 100).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(keys) > 0 {
|
||||
cacheKeys = append(cacheKeys, keys...)
|
||||
}
|
||||
@@ -174,27 +174,30 @@ func (m *customServerModel) ClearServerCache(ctx context.Context, serverId int64
|
||||
}
|
||||
|
||||
func (m *customServerModel) ClearServerAllCache(ctx context.Context) error {
|
||||
var cursor uint64
|
||||
var keys []string
|
||||
prefix := ServerConfigCacheKey + "*"
|
||||
for {
|
||||
scanKeys, newCursor, err := m.Cache.Scan(ctx, cursor, prefix, 999).Result()
|
||||
if err != nil {
|
||||
m.Logger.Error(ctx, fmt.Sprintf("ClearServerAllCache err:%v", err))
|
||||
break
|
||||
}
|
||||
m.Logger.Info(ctx, fmt.Sprintf("ClearServerAllCache query keys:%v", scanKeys))
|
||||
keys = append(keys, scanKeys...)
|
||||
cursor = newCursor
|
||||
if cursor == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(keys) > 0 {
|
||||
m.Logger.Info(ctx, fmt.Sprintf("ClearServerAllCache keys:%v", keys))
|
||||
return m.Cache.Del(ctx, keys...).Err()
|
||||
}
|
||||
return nil
|
||||
var cursor uint64
|
||||
var keys []string
|
||||
prefixes := []string{ServerConfigCacheKey + "*", ServerUserListCacheKey + "*"}
|
||||
for _, prefix := range prefixes {
|
||||
cursor = 0
|
||||
for {
|
||||
scanKeys, newCursor, err := m.Cache.Scan(ctx, cursor, prefix, 999).Result()
|
||||
if err != nil {
|
||||
m.Logger.Error(ctx, fmt.Sprintf("ClearServerAllCache err:%v", err))
|
||||
break
|
||||
}
|
||||
m.Logger.Info(ctx, fmt.Sprintf("ClearServerAllCache query keys:%v", scanKeys))
|
||||
keys = append(keys, scanKeys...)
|
||||
cursor = newCursor
|
||||
if cursor == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(keys) > 0 {
|
||||
m.Logger.Info(ctx, fmt.Sprintf("ClearServerAllCache keys:%v", keys))
|
||||
return m.Cache.Del(ctx, keys...).Err()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// InSet 支持多值 OR 查询
|
||||
|
||||
Reference in New Issue
Block a user