From c4b4bf92974f299ea523112a07ef4dadee7eeb5c Mon Sep 17 00:00:00 2001 From: "kim.dev.6789" Date: Thu, 15 Jan 2026 09:48:14 +0800 Subject: [PATCH] fix conflict --- pkg/common/storage/cache/cachekey/black.go | 29 ++++++++ .../storage/cache/cachekey/client_config.go | 10 +++ .../storage/cache/cachekey/conversation.go | 73 +++++++++++++++++++ pkg/common/storage/cache/cachekey/doc.go | 15 ++++ pkg/common/storage/cache/cachekey/friend.go | 48 ++++++++++++ pkg/common/storage/cache/cachekey/group.go | 70 ++++++++++++++++++ pkg/common/storage/cache/cachekey/msg.go | 32 ++++++++ pkg/common/storage/cache/cachekey/online.go | 62 ++++++++++++++++ pkg/common/storage/cache/cachekey/s3.go | 40 ++++++++++ pkg/common/storage/cache/cachekey/seq.go | 30 ++++++++ pkg/common/storage/cache/cachekey/third.go | 41 +++++++++++ pkg/common/storage/cache/cachekey/token.go | 33 +++++++++ pkg/common/storage/cache/cachekey/user.go | 28 +++++++ 13 files changed, 511 insertions(+) create mode 100644 pkg/common/storage/cache/cachekey/black.go create mode 100644 pkg/common/storage/cache/cachekey/client_config.go create mode 100644 pkg/common/storage/cache/cachekey/conversation.go create mode 100644 pkg/common/storage/cache/cachekey/doc.go create mode 100644 pkg/common/storage/cache/cachekey/friend.go create mode 100644 pkg/common/storage/cache/cachekey/group.go create mode 100644 pkg/common/storage/cache/cachekey/msg.go create mode 100644 pkg/common/storage/cache/cachekey/online.go create mode 100644 pkg/common/storage/cache/cachekey/s3.go create mode 100644 pkg/common/storage/cache/cachekey/seq.go create mode 100644 pkg/common/storage/cache/cachekey/third.go create mode 100644 pkg/common/storage/cache/cachekey/token.go create mode 100644 pkg/common/storage/cache/cachekey/user.go diff --git a/pkg/common/storage/cache/cachekey/black.go b/pkg/common/storage/cache/cachekey/black.go new file mode 100644 index 0000000..7d2ee27 --- /dev/null +++ b/pkg/common/storage/cache/cachekey/black.go @@ -0,0 +1,29 @@ +// Copyright © 2024 OpenIM. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cachekey + +const ( + BlackIDsKey = "BLACK_IDS:" + IsBlackKey = "IS_BLACK:" // local cache +) + +func GetBlackIDsKey(ownerUserID string) string { + return BlackIDsKey + ownerUserID + +} + +func GetIsBlackIDsKey(possibleBlackUserID, userID string) string { + return IsBlackKey + userID + "-" + possibleBlackUserID +} diff --git a/pkg/common/storage/cache/cachekey/client_config.go b/pkg/common/storage/cache/cachekey/client_config.go new file mode 100644 index 0000000..16770ad --- /dev/null +++ b/pkg/common/storage/cache/cachekey/client_config.go @@ -0,0 +1,10 @@ +package cachekey + +const ClientConfig = "CLIENT_CONFIG" + +func GetClientConfigKey(userID string) string { + if userID == "" { + return ClientConfig + } + return ClientConfig + ":" + userID +} diff --git a/pkg/common/storage/cache/cachekey/conversation.go b/pkg/common/storage/cache/cachekey/conversation.go new file mode 100644 index 0000000..9097742 --- /dev/null +++ b/pkg/common/storage/cache/cachekey/conversation.go @@ -0,0 +1,73 @@ +// Copyright © 2024 OpenIM. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cachekey + +const ( + ConversationKey = "CONVERSATION:" + ConversationIDsKey = "CONVERSATION_IDS:" + NotNotifyConversationIDsKey = "NOT_NOTIFY_CONVERSATION_IDS:" + PinnedConversationIDsKey = "PINNED_CONVERSATION_IDS:" + ConversationIDsHashKey = "CONVERSATION_IDS_HASH:" + ConversationHasReadSeqKey = "CONVERSATION_HAS_READ_SEQ:" + RecvMsgOptKey = "RECV_MSG_OPT:" + SuperGroupRecvMsgNotNotifyUserIDsKey = "SUPER_GROUP_RECV_MSG_NOT_NOTIFY_USER_IDS:" + SuperGroupRecvMsgNotNotifyUserIDsHashKey = "SUPER_GROUP_RECV_MSG_NOT_NOTIFY_USER_IDS_HASH:" + ConversationNotReceiveMessageUserIDsKey = "CONVERSATION_NOT_RECEIVE_MESSAGE_USER_IDS:" + ConversationUserMaxKey = "CONVERSATION_USER_MAX:" +) + +func GetConversationKey(ownerUserID, conversationID string) string { + return ConversationKey + ownerUserID + ":" + conversationID +} + +func GetConversationIDsKey(ownerUserID string) string { + return ConversationIDsKey + ownerUserID +} + +func GetNotNotifyConversationIDsKey(ownerUserID string) string { + return NotNotifyConversationIDsKey + ownerUserID +} + +func GetPinnedConversationIDs(ownerUserID string) string { + return PinnedConversationIDsKey + ownerUserID +} + +func GetSuperGroupRecvNotNotifyUserIDsKey(groupID string) string { + return SuperGroupRecvMsgNotNotifyUserIDsKey + groupID +} + +func GetRecvMsgOptKey(ownerUserID, conversationID string) string { + return RecvMsgOptKey + ownerUserID + ":" + conversationID +} + +func GetSuperGroupRecvNotNotifyUserIDsHashKey(groupID string) string { + return SuperGroupRecvMsgNotNotifyUserIDsHashKey + groupID +} + +func GetConversationHasReadSeqKey(ownerUserID, conversationID string) string { + return ConversationHasReadSeqKey + ownerUserID + ":" + conversationID +} + +func GetConversationNotReceiveMessageUserIDsKey(conversationID string) string { + return ConversationNotReceiveMessageUserIDsKey + conversationID +} + +func GetUserConversationIDsHashKey(ownerUserID string) string { + return ConversationIDsHashKey + ownerUserID +} + +func GetConversationUserMaxVersionKey(userID string) string { + return ConversationUserMaxKey + userID +} diff --git a/pkg/common/storage/cache/cachekey/doc.go b/pkg/common/storage/cache/cachekey/doc.go new file mode 100644 index 0000000..75ce156 --- /dev/null +++ b/pkg/common/storage/cache/cachekey/doc.go @@ -0,0 +1,15 @@ +// Copyright © 2024 OpenIM. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cachekey // import "git.imall.cloud/openim/open-im-server-deploy/pkg/common/storage/cache/cachekey" diff --git a/pkg/common/storage/cache/cachekey/friend.go b/pkg/common/storage/cache/cachekey/friend.go new file mode 100644 index 0000000..8a053ca --- /dev/null +++ b/pkg/common/storage/cache/cachekey/friend.go @@ -0,0 +1,48 @@ +// Copyright © 2024 OpenIM. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cachekey + +const ( + FriendIDsKey = "FRIEND_IDS:" + TwoWayFriendsIDsKey = "COMMON_FRIENDS_IDS:" + FriendKey = "FRIEND_INFO:" + IsFriendKey = "IS_FRIEND:" // local cache key + //FriendSyncSortUserIDsKey = "FRIEND_SYNC_SORT_USER_IDS:" + FriendMaxVersionKey = "FRIEND_MAX_VERSION:" +) + +func GetFriendIDsKey(ownerUserID string) string { + return FriendIDsKey + ownerUserID +} + +func GetTwoWayFriendsIDsKey(ownerUserID string) string { + return TwoWayFriendsIDsKey + ownerUserID +} + +func GetFriendKey(ownerUserID, friendUserID string) string { + return FriendKey + ownerUserID + "-" + friendUserID +} + +func GetFriendMaxVersionKey(ownerUserID string) string { + return FriendMaxVersionKey + ownerUserID +} + +func GetIsFriendKey(possibleFriendUserID, userID string) string { + return IsFriendKey + possibleFriendUserID + "-" + userID +} + +//func GetFriendSyncSortUserIDsKey(ownerUserID string, count int) string { +// return FriendSyncSortUserIDsKey + strconv.Itoa(count) + ":" + ownerUserID +//} diff --git a/pkg/common/storage/cache/cachekey/group.go b/pkg/common/storage/cache/cachekey/group.go new file mode 100644 index 0000000..72eb7c2 --- /dev/null +++ b/pkg/common/storage/cache/cachekey/group.go @@ -0,0 +1,70 @@ +// Copyright © 2024 OpenIM. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cachekey + +import ( + "strconv" + "time" +) + +const ( + groupExpireTime = time.Second * 60 * 60 * 12 + GroupInfoKey = "GROUP_INFO:" + GroupMemberIDsKey = "GROUP_MEMBER_IDS:" + GroupMembersHashKey = "GROUP_MEMBERS_HASH2:" + GroupMemberInfoKey = "GROUP_MEMBER_INFO:" + JoinedGroupsKey = "JOIN_GROUPS_KEY:" + GroupMemberNumKey = "GROUP_MEMBER_NUM_CACHE:" + GroupRoleLevelMemberIDsKey = "GROUP_ROLE_LEVEL_MEMBER_IDS:" + GroupAdminLevelMemberIDsKey = "GROUP_ADMIN_LEVEL_MEMBER_IDS:" + GroupMemberMaxVersionKey = "GROUP_MEMBER_MAX_VERSION:" + GroupJoinMaxVersionKey = "GROUP_JOIN_MAX_VERSION:" +) + +func GetGroupInfoKey(groupID string) string { + return GroupInfoKey + groupID +} + +func GetJoinedGroupsKey(userID string) string { + return JoinedGroupsKey + userID +} + +func GetGroupMembersHashKey(groupID string) string { + return GroupMembersHashKey + groupID +} + +func GetGroupMemberIDsKey(groupID string) string { + return GroupMemberIDsKey + groupID +} + +func GetGroupMemberInfoKey(groupID, userID string) string { + return GroupMemberInfoKey + groupID + "-" + userID +} + +func GetGroupMemberNumKey(groupID string) string { + return GroupMemberNumKey + groupID +} + +func GetGroupRoleLevelMemberIDsKey(groupID string, roleLevel int32) string { + return GroupRoleLevelMemberIDsKey + groupID + "-" + strconv.Itoa(int(roleLevel)) +} + +func GetGroupMemberMaxVersionKey(groupID string) string { + return GroupMemberMaxVersionKey + groupID +} + +func GetJoinGroupMaxVersionKey(userID string) string { + return GroupJoinMaxVersionKey + userID +} diff --git a/pkg/common/storage/cache/cachekey/msg.go b/pkg/common/storage/cache/cachekey/msg.go new file mode 100644 index 0000000..ac449df --- /dev/null +++ b/pkg/common/storage/cache/cachekey/msg.go @@ -0,0 +1,32 @@ +// Copyright © 2024 OpenIM. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cachekey + +import ( + "strconv" +) + +const ( + sendMsgFailedFlag = "SEND_MSG_FAILED_FLAG:" + messageCache = "MSG_CACHE:" +) + +func GetMsgCacheKey(conversationID string, seq int64) string { + return messageCache + conversationID + ":" + strconv.Itoa(int(seq)) +} + +func GetSendMsgKey(id string) string { + return sendMsgFailedFlag + id +} diff --git a/pkg/common/storage/cache/cachekey/online.go b/pkg/common/storage/cache/cachekey/online.go new file mode 100644 index 0000000..708ceca --- /dev/null +++ b/pkg/common/storage/cache/cachekey/online.go @@ -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) +} diff --git a/pkg/common/storage/cache/cachekey/s3.go b/pkg/common/storage/cache/cachekey/s3.go new file mode 100644 index 0000000..5c9540b --- /dev/null +++ b/pkg/common/storage/cache/cachekey/s3.go @@ -0,0 +1,40 @@ +// Copyright © 2024 OpenIM. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cachekey + +import "strconv" + +const ( + object = "OBJECT:" + s3 = "S3:" + minioImageInfo = "MINIO:IMAGE:" + minioThumbnail = "MINIO:THUMBNAIL:" +) + +func GetObjectKey(engine string, name string) string { + return object + engine + ":" + name +} + +func GetS3Key(engine string, name string) string { + return s3 + engine + ":" + name +} + +func GetObjectImageInfoKey(key string) string { + return minioImageInfo + key +} + +func GetMinioImageThumbnailKey(key string, format string, width int, height int) string { + return minioThumbnail + format + ":w" + strconv.Itoa(width) + ":h" + strconv.Itoa(height) + ":" + key +} diff --git a/pkg/common/storage/cache/cachekey/seq.go b/pkg/common/storage/cache/cachekey/seq.go new file mode 100644 index 0000000..b32e783 --- /dev/null +++ b/pkg/common/storage/cache/cachekey/seq.go @@ -0,0 +1,30 @@ +package cachekey + +const ( + MallocSeq = "MALLOC_SEQ:" + MallocMinSeqLock = "MALLOC_MIN_SEQ:" + + SeqUserMaxSeq = "SEQ_USER_MAX:" + SeqUserMinSeq = "SEQ_USER_MIN:" + SeqUserReadSeq = "SEQ_USER_READ:" +) + +func GetMallocSeqKey(conversationID string) string { + return MallocSeq + conversationID +} + +func GetMallocMinSeqKey(conversationID string) string { + return MallocMinSeqLock + conversationID +} + +func GetSeqUserMaxSeqKey(conversationID string, userID string) string { + return SeqUserMaxSeq + conversationID + ":" + userID +} + +func GetSeqUserMinSeqKey(conversationID string, userID string) string { + return SeqUserMinSeq + conversationID + ":" + userID +} + +func GetSeqUserReadSeqKey(conversationID string, userID string) string { + return SeqUserReadSeq + conversationID + ":" + userID +} diff --git a/pkg/common/storage/cache/cachekey/third.go b/pkg/common/storage/cache/cachekey/third.go new file mode 100644 index 0000000..469900c --- /dev/null +++ b/pkg/common/storage/cache/cachekey/third.go @@ -0,0 +1,41 @@ +// Copyright © 2024 OpenIM. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cachekey + +import ( + "strconv" +) + +const ( + getuiToken = "GETUI_TOKEN" + getuiTaskID = "GETUI_TASK_ID" + fmcToken = "FCM_TOKEN:" + userBadgeUnreadCountSum = "USER_BADGE_UNREAD_COUNT_SUM:" +) + +func GetFcmAccountTokenKey(account string, platformID int) string { + return fmcToken + account + ":" + strconv.Itoa(platformID) +} + +func GetUserBadgeUnreadCountSumKey(userID string) string { + return userBadgeUnreadCountSum + userID +} + +func GetGetuiTokenKey() string { + return getuiToken +} +func GetGetuiTaskIDKey() string { + return getuiTaskID +} diff --git a/pkg/common/storage/cache/cachekey/token.go b/pkg/common/storage/cache/cachekey/token.go new file mode 100644 index 0000000..e965ac7 --- /dev/null +++ b/pkg/common/storage/cache/cachekey/token.go @@ -0,0 +1,33 @@ +package cachekey + +import ( + "strings" + + "git.imall.cloud/openim/protocol/constant" +) + +const ( + UidPidToken = "UID_PID_TOKEN_STATUS:" +) + +func GetTokenKey(userID string, platformID int) string { + return UidPidToken + userID + ":" + constant.PlatformIDToName(platformID) +} + +func GetTemporaryTokenKey(userID string, platformID int, token string) string { + return UidPidToken + ":TEMPORARY:" + userID + ":" + constant.PlatformIDToName(platformID) + ":" + token +} + +func GetAllPlatformTokenKey(userID string) []string { + res := make([]string, len(constant.PlatformID2Name)) + for k := range constant.PlatformID2Name { + res[k-1] = GetTokenKey(userID, k) + } + return res +} + +func GetPlatformIDByTokenKey(key string) int { + splitKey := strings.Split(key, ":") + platform := splitKey[len(splitKey)-1] + return constant.PlatformNameToID(platform) +} diff --git a/pkg/common/storage/cache/cachekey/user.go b/pkg/common/storage/cache/cachekey/user.go new file mode 100644 index 0000000..473ca1b --- /dev/null +++ b/pkg/common/storage/cache/cachekey/user.go @@ -0,0 +1,28 @@ +// Copyright © 2024 OpenIM. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cachekey + +const ( + UserInfoKey = "USER_INFO:" + UserGlobalRecvMsgOptKey = "USER_GLOBAL_RECV_MSG_OPT_KEY:" +) + +func GetUserInfoKey(userID string) string { + return UserInfoKey + userID +} + +func GetUserGlobalRecvMsgOptKey(userID string) string { + return UserGlobalRecvMsgOptKey + userID +}