fix conflict
Some checks failed
itom-platform auto build image / build (push) Failing after 0s

This commit is contained in:
kim.dev.6789
2026-01-15 09:48:14 +08:00
parent 843e32fe55
commit c4b4bf9297
13 changed files with 511 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
package cachekey
import (
"strings"
"time"
)
const (
onlineKeyBase = "ONLINE:"
onlineChannelBase = "online_change"
OnlineExpire = time.Hour / 2
// OnlineUserCountKey 在线人数缓存键
onlineUserCountKeyBase = "ONLINE_USER_COUNT"
// OnlineUserCountHistoryKey 在线人数历史缓存键
onlineUserCountHistoryKeyBase = "ONLINE_USER_COUNT_HISTORY"
// OnlineUserCountHistoryRetention 在线人数历史保留时长
OnlineUserCountHistoryRetention = 60 * 24 * time.Hour
)
var (
OnlineKey = onlineKeyBase
OnlineChannel = onlineChannelBase
OnlineUserCountKey = onlineUserCountKeyBase
OnlineUserCountHistoryKey = onlineUserCountHistoryKeyBase
)
func SetOnlinePrefix(prefix string, useHashTag bool, redisMode string) {
normalized := normalizeOnlinePrefix(prefix, useHashTag, redisMode)
if normalized == "" {
OnlineKey = onlineKeyBase
OnlineChannel = onlineChannelBase
OnlineUserCountKey = onlineUserCountKeyBase
OnlineUserCountHistoryKey = onlineUserCountHistoryKeyBase
return
}
OnlineKey = normalized + onlineKeyBase
OnlineChannel = normalized + onlineChannelBase
OnlineUserCountKey = normalized + onlineUserCountKeyBase
OnlineUserCountHistoryKey = normalized + onlineUserCountHistoryKeyBase
}
func normalizeOnlinePrefix(prefix string, useHashTag bool, redisMode string) string {
prefix = strings.TrimSpace(prefix)
if prefix == "" {
return ""
}
prefix = strings.TrimSuffix(prefix, ":")
if useHashTag || strings.EqualFold(redisMode, "cluster") {
if !(strings.HasPrefix(prefix, "{") && strings.HasSuffix(prefix, "}")) {
prefix = "{" + prefix + "}"
}
}
return prefix + ":"
}
func GetOnlineKey(userID string) string {
return OnlineKey + userID
}
func GetOnlineKeyUserID(key string) string {
return strings.TrimPrefix(key, OnlineKey)
}