mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-02 08:05:58 +08:00
errcode
This commit is contained in:
Vendored
+1
@@ -15,6 +15,7 @@ const (
|
||||
blackExpireTime = time.Second * 60 * 60 * 12
|
||||
)
|
||||
|
||||
// args fn will exec when no data in cache
|
||||
type BlackCache interface {
|
||||
//get blackIDs from cache
|
||||
GetBlackIDs(ctx context.Context, userID string, fn func(ctx context.Context, userID string) ([]string, error)) (blackIDs []string, err error)
|
||||
|
||||
Vendored
+1
@@ -21,6 +21,7 @@ const (
|
||||
conversationExpireTime = time.Second * 60 * 60 * 12
|
||||
)
|
||||
|
||||
// args fn will exec when no data in cache
|
||||
type ConversationCache interface {
|
||||
// get user's conversationIDs from cache
|
||||
GetUserConversationIDs(ctx context.Context, userID string, fn func(ctx context.Context, userID string) ([]string, error)) ([]string, error)
|
||||
|
||||
+36
-2
@@ -1,13 +1,47 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/db/table/unrelation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/dtm-labs/rockscache"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ExtendMsgSetCache struct {
|
||||
friendDB *relation.FriendGorm
|
||||
expireTime time.Duration
|
||||
rcClient *rockscache.Client
|
||||
}
|
||||
|
||||
func (e *ExtendMsgSetCache) GetExtendMsg(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, firstModifyTime int64) (extendMsg *unrelation.ExtendMsg, err error) {
|
||||
getExtendMsg := func() (string, error) {
|
||||
extendMsg, err := db.DB.GetExtendMsg(sourceID, sessionType, clientMsgID, firstModifyTime)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "GetExtendMsgList failed")
|
||||
}
|
||||
bytes, err := json.Marshal(extendMsg)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "Marshal failed")
|
||||
}
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "sourceID", sourceID, "sessionType",
|
||||
sessionType, "clientMsgID", clientMsgID, "firstModifyTime", firstModifyTime, "extendMsg", extendMsg)
|
||||
}()
|
||||
extendMsgStr, err := db.DB.Rc.Fetch(extendMsgCache+clientMsgID, time.Second*30*60, getExtendMsg)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "Fetch failed")
|
||||
}
|
||||
extendMsg = &mongoDB.ExtendMsg{}
|
||||
err = json.Unmarshal([]byte(extendMsgStr), extendMsg)
|
||||
return extendMsg, utils.Wrap(err, "Unmarshal failed")
|
||||
}
|
||||
|
||||
func (e *ExtendMsgSetCache) DelExtendMsg(ctx context.Context, clientMsgID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "clientMsgID", clientMsgID)
|
||||
}()
|
||||
return utils.Wrap(db.DB.Rc.TagAsDeleted(extendMsgCache+clientMsgID), "DelExtendMsg err")
|
||||
}
|
||||
|
||||
Vendored
+3
-1
@@ -19,12 +19,14 @@ const (
|
||||
friendKey = "FRIEND_INFO:"
|
||||
)
|
||||
|
||||
// args fn will exec when no data in cache
|
||||
type FriendCache interface {
|
||||
GetFriendIDs(ctx context.Context, ownerUserID string, fn func(ctx context.Context, ownerUserID string) (friendIDs []string, err error)) (friendIDs []string, err error)
|
||||
// call when friendID List changed
|
||||
DelFriendIDs(ctx context.Context, ownerUserID string) (err error)
|
||||
// get single friendInfo from cache
|
||||
GetFriend(ctx context.Context, ownerUserID, friendUserID string, fn func(ctx context.Context, ownerUserID, friendUserID string) (friend *relationTb.FriendModel, err error)) (friend *relationTb.FriendModel, err error)
|
||||
// del friend when friend info changed or remove it
|
||||
// del friend when friend info changed
|
||||
DelFriend(ctx context.Context, ownerUserID, friendUserID string) (err error)
|
||||
}
|
||||
|
||||
|
||||
Vendored
+26
-26
@@ -52,40 +52,40 @@ func NewGroupCacheRedis(rdb redis.UniversalClient, groupDB *relation.GroupGorm,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GroupCache) getRedisClient() *RedisClient {
|
||||
func (g *GroupCacheRedis) getRedisClient() *RedisClient {
|
||||
return g.redisClient
|
||||
}
|
||||
|
||||
func (g *GroupCache) getGroupInfoKey(groupID string) string {
|
||||
func (g *GroupCacheRedis) getGroupInfoKey(groupID string) string {
|
||||
return groupInfoKey + groupID
|
||||
}
|
||||
|
||||
func (g *GroupCache) getJoinedSuperGroupsIDKey(userID string) string {
|
||||
func (g *GroupCacheRedis) getJoinedSuperGroupsIDKey(userID string) string {
|
||||
return joinedSuperGroupsKey + userID
|
||||
}
|
||||
|
||||
func (g *GroupCache) getJoinedGroupsKey(userID string) string {
|
||||
func (g *GroupCacheRedis) getJoinedGroupsKey(userID string) string {
|
||||
return joinedGroupsKey + userID
|
||||
}
|
||||
|
||||
func (g *GroupCache) getGroupMembersHashKey(groupID string) string {
|
||||
func (g *GroupCacheRedis) getGroupMembersHashKey(groupID string) string {
|
||||
return groupMembersHashKey + groupID
|
||||
}
|
||||
|
||||
func (g *GroupCache) getGroupMemberIDsKey(groupID string) string {
|
||||
func (g *GroupCacheRedis) getGroupMemberIDsKey(groupID string) string {
|
||||
return groupMemberIDsKey + groupID
|
||||
}
|
||||
|
||||
func (g *GroupCache) getGroupMemberInfoKey(groupID, userID string) string {
|
||||
func (g *GroupCacheRedis) getGroupMemberInfoKey(groupID, userID string) string {
|
||||
return groupMemberInfoKey + groupID + "-" + userID
|
||||
}
|
||||
|
||||
func (g *GroupCache) getGroupMemberNumKey(groupID string) string {
|
||||
func (g *GroupCacheRedis) getGroupMemberNumKey(groupID string) string {
|
||||
return groupMemberNumKey + groupID
|
||||
}
|
||||
|
||||
// / groupInfo
|
||||
func (g *GroupCache) GetGroupsInfo(ctx context.Context, groupIDs []string) (groups []*relation.Group, err error) {
|
||||
func (g *GroupCacheRedis) GetGroupsInfo(ctx context.Context, groupIDs []string) (groups []*relation.Group, err error) {
|
||||
for _, groupID := range groupIDs {
|
||||
group, err := g.GetGroupInfo(ctx, groupID)
|
||||
if err != nil {
|
||||
@@ -96,7 +96,7 @@ func (g *GroupCache) GetGroupsInfo(ctx context.Context, groupIDs []string) (grou
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
func (g *GroupCache) GetGroupInfo(ctx context.Context, groupID string) (group *relation.GroupGorm, err error) {
|
||||
func (g *GroupCacheRedis) GetGroupInfo(ctx context.Context, groupID string) (group *relation.GroupGorm, err error) {
|
||||
getGroup := func() (string, error) {
|
||||
groupInfo, err := g.group.Take(ctx, groupID)
|
||||
if err != nil {
|
||||
@@ -120,14 +120,14 @@ func (g *GroupCache) GetGroupInfo(ctx context.Context, groupID string) (group *r
|
||||
return group, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelGroupInfo(ctx context.Context, groupID string) (err error) {
|
||||
func (g *GroupCacheRedis) DelGroupInfo(ctx context.Context, groupID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
}()
|
||||
return g.rcClient.TagAsDeleted(g.getGroupInfoKey(groupID))
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelGroupsInfo(ctx context.Context, groupIDs []string) error {
|
||||
func (g *GroupCacheRedis) DelGroupsInfo(ctx context.Context, groupIDs []string) error {
|
||||
for _, groupID := range groupIDs {
|
||||
if err := g.DelGroupInfo(ctx, groupID); err != nil {
|
||||
return err
|
||||
@@ -137,7 +137,7 @@ func (g *GroupCache) DelGroupsInfo(ctx context.Context, groupIDs []string) error
|
||||
}
|
||||
|
||||
// userJoinSuperGroup
|
||||
func (g *GroupCache) BatchDelJoinedSuperGroupIDs(ctx context.Context, userIDs []string) (err error) {
|
||||
func (g *GroupCacheRedis) BatchDelJoinedSuperGroupIDs(ctx context.Context, userIDs []string) (err error) {
|
||||
for _, userID := range userIDs {
|
||||
if err := g.DelJoinedSuperGroupIDs(ctx, userID); err != nil {
|
||||
return err
|
||||
@@ -146,14 +146,14 @@ func (g *GroupCache) BatchDelJoinedSuperGroupIDs(ctx context.Context, userIDs []
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelJoinedSuperGroupIDs(ctx context.Context, userID string) (err error) {
|
||||
func (g *GroupCacheRedis) DelJoinedSuperGroupIDs(ctx context.Context, userID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
}()
|
||||
return g.rcClient.TagAsDeleted(g.getJoinedSuperGroupsIDKey(userID))
|
||||
}
|
||||
|
||||
func (g *GroupCache) GetJoinedSuperGroupIDs(ctx context.Context, userID string) (joinedSuperGroupIDs []string, err error) {
|
||||
func (g *GroupCacheRedis) GetJoinedSuperGroupIDs(ctx context.Context, userID string) (joinedSuperGroupIDs []string, err error) {
|
||||
getJoinedSuperGroupIDList := func() (string, error) {
|
||||
userToSuperGroup, err := g.mongoDB.GetSuperGroupByUserID(ctx, userID)
|
||||
if err != nil {
|
||||
@@ -177,7 +177,7 @@ func (g *GroupCache) GetJoinedSuperGroupIDs(ctx context.Context, userID string)
|
||||
}
|
||||
|
||||
// groupMembersHash
|
||||
func (g *GroupCache) GetGroupMembersHash(ctx context.Context, groupID string) (hashCodeUint64 uint64, err error) {
|
||||
func (g *GroupCacheRedis) GetGroupMembersHash(ctx context.Context, groupID string) (hashCodeUint64 uint64, err error) {
|
||||
generateHash := func() (string, error) {
|
||||
groupInfo, err := g.GetGroupInfo(ctx, groupID)
|
||||
if err != nil {
|
||||
@@ -210,7 +210,7 @@ func (g *GroupCache) GetGroupMembersHash(ctx context.Context, groupID string) (h
|
||||
return uint64(hashCode), err
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelGroupMembersHash(ctx context.Context, groupID string) (err error) {
|
||||
func (g *GroupCacheRedis) DelGroupMembersHash(ctx context.Context, groupID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
}()
|
||||
@@ -219,7 +219,7 @@ func (g *GroupCache) DelGroupMembersHash(ctx context.Context, groupID string) (e
|
||||
|
||||
// groupMemberIDs
|
||||
// from redis
|
||||
func (g *GroupCache) GetGroupMemberIDs(ctx context.Context, groupID string) (groupMemberIDs []string, err error) {
|
||||
func (g *GroupCacheRedis) GetGroupMemberIDs(ctx context.Context, groupID string) (groupMemberIDs []string, err error) {
|
||||
f := func() (string, error) {
|
||||
groupInfo, err := g.GetGroupInfo(ctx, groupID)
|
||||
if err != nil {
|
||||
@@ -255,7 +255,7 @@ func (g *GroupCache) GetGroupMemberIDs(ctx context.Context, groupID string) (gro
|
||||
return groupMemberIDs, nil
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelGroupMemberIDs(ctx context.Context, groupID string) (err error) {
|
||||
func (g *GroupCacheRedis) DelGroupMemberIDs(ctx context.Context, groupID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
}()
|
||||
@@ -263,7 +263,7 @@ func (g *GroupCache) DelGroupMemberIDs(ctx context.Context, groupID string) (err
|
||||
}
|
||||
|
||||
// JoinedGroups
|
||||
func (g *GroupCache) GetJoinedGroupIDs(ctx context.Context, userID string) (joinedGroupIDs []string, err error) {
|
||||
func (g *GroupCacheRedis) GetJoinedGroupIDs(ctx context.Context, userID string) (joinedGroupIDs []string, err error) {
|
||||
getJoinedGroupIDList := func() (string, error) {
|
||||
joinedGroupList, err := relation.GetJoinedGroupIDListByUserID(userID)
|
||||
if err != nil {
|
||||
@@ -286,7 +286,7 @@ func (g *GroupCache) GetJoinedGroupIDs(ctx context.Context, userID string) (join
|
||||
return joinedGroupIDs, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelJoinedGroupIDs(ctx context.Context, userID string) (err error) {
|
||||
func (g *GroupCacheRedis) DelJoinedGroupIDs(ctx context.Context, userID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
}()
|
||||
@@ -294,7 +294,7 @@ func (g *GroupCache) DelJoinedGroupIDs(ctx context.Context, userID string) (err
|
||||
}
|
||||
|
||||
// GetGroupMemberInfo
|
||||
func (g *GroupCache) GetGroupMemberInfo(ctx context.Context, groupID, userID string) (groupMember *relation.GroupMember, err error) {
|
||||
func (g *GroupCacheRedis) GetGroupMemberInfo(ctx context.Context, groupID, userID string) (groupMember *relation.GroupMember, err error) {
|
||||
getGroupMemberInfo := func() (string, error) {
|
||||
groupMemberInfo, err := relation.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
|
||||
if err != nil {
|
||||
@@ -318,7 +318,7 @@ func (g *GroupCache) GetGroupMemberInfo(ctx context.Context, groupID, userID str
|
||||
return groupMember, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func (g *GroupCache) GetGroupMembersInfo(ctx context.Context, count, offset int32, groupID string) (groupMembers []*relation.GroupMember, err error) {
|
||||
func (g *GroupCacheRedis) GetGroupMembersInfo(ctx context.Context, count, offset int32, groupID string) (groupMembers []*relation.GroupMember, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "count", count, "offset", offset, "groupID", groupID, "groupMember", groupMembers)
|
||||
}()
|
||||
@@ -363,7 +363,7 @@ func (g *GroupCache) GetGroupMembersInfo(ctx context.Context, count, offset int3
|
||||
return groupMemberList, nil
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelGroupMemberInfo(ctx context.Context, groupID, userID string) (err error) {
|
||||
func (g *GroupCacheRedis) DelGroupMemberInfo(ctx context.Context, groupID, userID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID)
|
||||
}()
|
||||
@@ -371,7 +371,7 @@ func (g *GroupCache) DelGroupMemberInfo(ctx context.Context, groupID, userID str
|
||||
}
|
||||
|
||||
// groupMemberNum
|
||||
func (g *GroupCache) GetGroupMemberNum(ctx context.Context, groupID string) (num int, err error) {
|
||||
func (g *GroupCacheRedis) GetGroupMemberNum(ctx context.Context, groupID string) (num int, err error) {
|
||||
getGroupMemberNum := func() (string, error) {
|
||||
num, err := relation.GetGroupMemberNumByGroupID(groupID)
|
||||
if err != nil {
|
||||
@@ -389,7 +389,7 @@ func (g *GroupCache) GetGroupMemberNum(ctx context.Context, groupID string) (num
|
||||
return strconv.Atoi(groupMember)
|
||||
}
|
||||
|
||||
func (g *GroupCache) DelGroupMemberNum(ctx context.Context, groupID string) (err error) {
|
||||
func (g *GroupCacheRedis) DelGroupMemberNum(ctx context.Context, groupID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
|
||||
}()
|
||||
|
||||
Vendored
+38
-71
@@ -20,28 +20,36 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
accountTempCode = "ACCOUNT_TEMP_CODE"
|
||||
resetPwdTempCode = "RESET_PWD_TEMP_CODE"
|
||||
userIncrSeq = "REDIS_USER_INCR_SEQ:" // user incr seq
|
||||
appleDeviceToken = "DEVICE_TOKEN"
|
||||
userMinSeq = "REDIS_USER_MIN_SEQ:"
|
||||
uidPidToken = "UID_PID_TOKEN_STATUS:"
|
||||
conversationReceiveMessageOpt = "CON_RECV_MSG_OPT:"
|
||||
getuiToken = "GETUI_TOKEN"
|
||||
getuiTaskID = "GETUI_TASK_ID"
|
||||
messageCache = "MESSAGE_CACHE:"
|
||||
SignalCache = "SIGNAL_CACHE:"
|
||||
SignalListCache = "SIGNAL_LIST_CACHE:"
|
||||
GlobalMsgRecvOpt = "GLOBAL_MSG_RECV_OPT"
|
||||
FcmToken = "FCM_TOKEN:"
|
||||
groupUserMinSeq = "GROUP_USER_MIN_SEQ:"
|
||||
groupMaxSeq = "GROUP_MAX_SEQ:"
|
||||
groupMinSeq = "GROUP_MIN_SEQ:"
|
||||
sendMsgFailedFlag = "SEND_MSG_FAILED_FLAG:"
|
||||
userBadgeUnreadCountSum = "USER_BADGE_UNREAD_COUNT_SUM:"
|
||||
exTypeKeyLocker = "EX_LOCK:"
|
||||
userIncrSeq = "REDIS_USER_INCR_SEQ:" // user incr seq
|
||||
appleDeviceToken = "DEVICE_TOKEN"
|
||||
userMinSeq = "REDIS_USER_MIN_SEQ:"
|
||||
uidPidToken = "UID_PID_TOKEN_STATUS:"
|
||||
getuiToken = "GETUI_TOKEN"
|
||||
getuiTaskID = "GETUI_TASK_ID"
|
||||
messageCache = "MESSAGE_CACHE:"
|
||||
signalCache = "SIGNAL_CACHE:"
|
||||
signalListCache = "SIGNAL_LIST_CACHE:"
|
||||
FcmToken = "FCM_TOKEN:"
|
||||
groupUserMinSeq = "GROUP_USER_MIN_SEQ:"
|
||||
groupMaxSeq = "GROUP_MAX_SEQ:"
|
||||
groupMinSeq = "GROUP_MIN_SEQ:"
|
||||
sendMsgFailedFlag = "SEND_MSG_FAILED_FLAG:"
|
||||
userBadgeUnreadCountSum = "USER_BADGE_UNREAD_COUNT_SUM:"
|
||||
exTypeKeyLocker = "EX_LOCK:"
|
||||
)
|
||||
|
||||
type Cache interface {
|
||||
IncrUserSeq(uid string) (uint64, error)
|
||||
GetUserMaxSeq(uid string) (uint64, error)
|
||||
SetUserMaxSeq(uid string, maxSeq uint64) error
|
||||
SetUserMinSeq(uid string, minSeq uint32) (err error)
|
||||
GetUserMinSeq(uid string) (uint64, error)
|
||||
SetGroupUserMinSeq(groupID, userID string, minSeq uint64) (err error)
|
||||
GetGroupUserMinSeq(groupID, userID string) (uint64, error)
|
||||
}
|
||||
|
||||
// native redis operate
|
||||
|
||||
type RedisClient struct {
|
||||
rdb redis.UniversalClient
|
||||
}
|
||||
@@ -86,25 +94,6 @@ func NewRedisClient(rdb redis.UniversalClient) *RedisClient {
|
||||
return &RedisClient{rdb: rdb}
|
||||
}
|
||||
|
||||
func (r *RedisClient) JudgeAccountEXISTS(account string) (bool, error) {
|
||||
key := accountTempCode + account
|
||||
n, err := r.rdb.Exists(context.Background(), key).Result()
|
||||
if n > 0 {
|
||||
return true, err
|
||||
} else {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RedisClient) SetAccountCode(account string, code, ttl int) (err error) {
|
||||
key := accountTempCode + account
|
||||
return r.rdb.Set(context.Background(), key, code, time.Duration(ttl)*time.Second).Err()
|
||||
}
|
||||
func (r *RedisClient) GetAccountCode(account string) (string, error) {
|
||||
key := accountTempCode + account
|
||||
return r.rdb.Get(context.Background(), key).Result()
|
||||
}
|
||||
|
||||
//Perform seq auto-increment operation of user messages
|
||||
func (r *RedisClient) IncrUserSeq(uid string) (uint64, error) {
|
||||
key := userIncrSeq + uid
|
||||
@@ -195,36 +184,12 @@ func (r *RedisClient) SetTokenMapByUidPid(userID string, platformID int, m map[s
|
||||
}
|
||||
return r.rdb.HSet(context.Background(), key, mm).Err()
|
||||
}
|
||||
|
||||
func (r *RedisClient) DeleteTokenByUidPid(userID string, platformID int, fields []string) error {
|
||||
key := uidPidToken + userID + ":" + constant.PlatformIDToName(platformID)
|
||||
return r.rdb.HDel(context.Background(), key, fields...).Err()
|
||||
}
|
||||
func (r *RedisClient) SetSingleConversationRecvMsgOpt(userID, conversationID string, opt int32) error {
|
||||
key := conversationReceiveMessageOpt + userID
|
||||
return r.rdb.HSet(context.Background(), key, conversationID, opt).Err()
|
||||
}
|
||||
|
||||
func (r *RedisClient) GetSingleConversationRecvMsgOpt(userID, conversationID string) (int, error) {
|
||||
key := conversationReceiveMessageOpt + userID
|
||||
result, err := r.rdb.HGet(context.Background(), key, conversationID).Result()
|
||||
return utils.StringToInt(result), err
|
||||
}
|
||||
func (r *RedisClient) SetUserGlobalMsgRecvOpt(userID string, opt int32) error {
|
||||
key := conversationReceiveMessageOpt + userID
|
||||
return r.rdb.HSet(context.Background(), key, GlobalMsgRecvOpt, opt).Err()
|
||||
}
|
||||
func (r *RedisClient) GetUserGlobalMsgRecvOpt(userID string) (int, error) {
|
||||
key := conversationReceiveMessageOpt + userID
|
||||
result, err := r.rdb.HGet(context.Background(), key, GlobalMsgRecvOpt).Result()
|
||||
if err != nil {
|
||||
if err == redis.Nil {
|
||||
return 0, nil
|
||||
} else {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return utils.StringToInt(result), err
|
||||
}
|
||||
func (r *RedisClient) GetMessageListBySeq(userID string, seqList []uint32, operationID string) (seqMsg []*pbCommon.MsgData, failedSeqList []uint32, errResult error) {
|
||||
for _, v := range seqList {
|
||||
//MESSAGE_CACHE:169.254.225.224_reliability1653387820_0_1
|
||||
@@ -336,7 +301,7 @@ func (r *RedisClient) HandleSignalInfo(operationID string, msg *pbCommon.MsgData
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
keyList := SignalListCache + userID
|
||||
keyList := signalListCache + userID
|
||||
err = r.rdb.LPush(context.Background(), keyList, msg.ClientMsgID).Err()
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -345,7 +310,7 @@ func (r *RedisClient) HandleSignalInfo(operationID string, msg *pbCommon.MsgData
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
key := SignalCache + msg.ClientMsgID
|
||||
key := signalCache + msg.ClientMsgID
|
||||
err = r.rdb.Set(context.Background(), key, msg.Content, time.Duration(timeout)*time.Second).Err()
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -356,7 +321,7 @@ func (r *RedisClient) HandleSignalInfo(operationID string, msg *pbCommon.MsgData
|
||||
}
|
||||
|
||||
func (r *RedisClient) GetSignalInfoFromCacheByClientMsgID(clientMsgID string) (invitationInfo *pbRtc.SignalInviteReq, err error) {
|
||||
key := SignalCache + clientMsgID
|
||||
key := signalCache + clientMsgID
|
||||
invitationInfo = &pbRtc.SignalInviteReq{}
|
||||
bytes, err := r.rdb.Get(context.Background(), key).Bytes()
|
||||
if err != nil {
|
||||
@@ -378,7 +343,7 @@ func (r *RedisClient) GetSignalInfoFromCacheByClientMsgID(clientMsgID string) (i
|
||||
}
|
||||
|
||||
func (r *RedisClient) GetAvailableSignalInvitationInfo(userID string) (invitationInfo *pbRtc.SignalInviteReq, err error) {
|
||||
keyList := SignalListCache + userID
|
||||
keyList := signalListCache + userID
|
||||
result := r.rdb.LPop(context.Background(), keyList)
|
||||
if err = result.Err(); err != nil {
|
||||
return nil, utils.Wrap(err, "GetAvailableSignalInvitationInfo failed")
|
||||
@@ -400,7 +365,7 @@ func (r *RedisClient) GetAvailableSignalInvitationInfo(userID string) (invitatio
|
||||
}
|
||||
|
||||
func (r *RedisClient) DelUserSignalList(userID string) error {
|
||||
keyList := SignalListCache + userID
|
||||
keyList := signalListCache + userID
|
||||
err := r.rdb.Del(context.Background(), keyList).Err()
|
||||
return err
|
||||
}
|
||||
@@ -516,17 +481,19 @@ func (r *RedisClient) SetMessageReactionExpire(clientMsgID string, sessionType i
|
||||
key := getMessageReactionExPrefix(clientMsgID, sessionType)
|
||||
return r.rdb.Expire(context.Background(), key, expiration).Result()
|
||||
}
|
||||
|
||||
func (r *RedisClient) GetMessageTypeKeyValue(clientMsgID string, sessionType int32, typeKey string) (string, error) {
|
||||
key := getMessageReactionExPrefix(clientMsgID, sessionType)
|
||||
result, err := r.rdb.HGet(context.Background(), key, typeKey).Result()
|
||||
return result, err
|
||||
|
||||
}
|
||||
|
||||
func (r *RedisClient) SetMessageTypeKeyValue(clientMsgID string, sessionType int32, typeKey, value string) error {
|
||||
key := getMessageReactionExPrefix(clientMsgID, sessionType)
|
||||
return r.rdb.HSet(context.Background(), key, typeKey, value).Err()
|
||||
|
||||
}
|
||||
|
||||
func (r *RedisClient) LockMessageTypeKey(clientMsgID string, TypeKey string) error {
|
||||
key := exTypeKeyLocker + clientMsgID + "_" + TypeKey
|
||||
return r.rdb.SetNX(context.Background(), key, 1, time.Minute).Err()
|
||||
@@ -537,7 +504,7 @@ func (r *RedisClient) UnLockMessageTypeKey(clientMsgID string, TypeKey string) e
|
||||
|
||||
}
|
||||
|
||||
func getMessageReactionExPrefix(clientMsgID string, sessionType int32) string {
|
||||
func (r *RedisClient) getMessageReactionExPrefix(clientMsgID string, sessionType int32) string {
|
||||
switch sessionType {
|
||||
case constant.SingleChatType:
|
||||
return "EX_SINGLE_" + clientMsgID
|
||||
|
||||
Vendored
+9
-44
@@ -3,7 +3,7 @@ package cache
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
server_api_params "Open_IM/pkg/proto/sdk_ws"
|
||||
common "Open_IM/pkg/proto/sdk_ws"
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var DB RedisClient
|
||||
|
||||
func Test_SetTokenMapByUidPid(t *testing.T) {
|
||||
m := make(map[string]int, 0)
|
||||
m["test1"] = 1
|
||||
@@ -35,7 +37,7 @@ func Test_GetKeyTTL(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
key := flag.String("key", "key", "key value")
|
||||
flag.Parse()
|
||||
ttl, err := DB.RDB.TTL(ctx, *key).Result()
|
||||
ttl, err := DB.GetClient().TTL(ctx, *key).Result()
|
||||
assert.Nil(t, err)
|
||||
fmt.Println(ttl)
|
||||
}
|
||||
@@ -43,7 +45,7 @@ func Test_HGetAll(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
key := flag.String("key", "key", "key value")
|
||||
flag.Parse()
|
||||
ttl, err := DB.RDB.TTL(ctx, *key).Result()
|
||||
ttl, err := DB.GetClient().TTL(ctx, *key).Result()
|
||||
assert.Nil(t, err)
|
||||
fmt.Println(ttl)
|
||||
}
|
||||
@@ -51,14 +53,14 @@ func Test_HGetAll(t *testing.T) {
|
||||
func Test_NewSetMessageToCache(t *testing.T) {
|
||||
var msg pbChat.MsgDataToMQ
|
||||
m := make(map[string]bool)
|
||||
var offlinePush server_api_params.OfflinePushInfo
|
||||
var offlinePush common.OfflinePushInfo
|
||||
offlinePush.Title = "3"
|
||||
offlinePush.Ex = "34"
|
||||
offlinePush.IOSPushSound = "+1"
|
||||
offlinePush.IOSBadgeCount = true
|
||||
m[constant.IsPersistent] = true
|
||||
m[constant.IsHistory] = true
|
||||
var data server_api_params.MsgData
|
||||
var data common.MsgData
|
||||
uid := "test_uid"
|
||||
data.Seq = 11
|
||||
data.ClientMsgID = "23jwhjsdf"
|
||||
@@ -77,7 +79,7 @@ func Test_NewSetMessageToCache(t *testing.T) {
|
||||
}
|
||||
func Test_NewGetMessageListBySeq(t *testing.T) {
|
||||
var msg pbChat.MsgDataToMQ
|
||||
var data server_api_params.MsgData
|
||||
var data common.MsgData
|
||||
uid := "test_uid"
|
||||
data.Seq = 11
|
||||
data.ClientMsgID = "23jwhjsdf"
|
||||
@@ -88,37 +90,7 @@ func Test_NewGetMessageListBySeq(t *testing.T) {
|
||||
fmt.Println(seqMsg, failedSeqList)
|
||||
|
||||
}
|
||||
func Test_SetUserGlobalMsgRecvOpt(t *testing.T) {
|
||||
var opt int32
|
||||
uid := "test_uid"
|
||||
opt = 1
|
||||
err := DB.SetUserGlobalMsgRecvOpt(uid, opt)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
func Test_GetUserGlobalMsgRecvOpt(t *testing.T) {
|
||||
uid := "test_uid"
|
||||
opt, err := DB.GetUserGlobalMsgRecvOpt(uid)
|
||||
assert.Nil(t, err)
|
||||
fmt.Println("get opt", opt)
|
||||
}
|
||||
func Test_JudgeAccountEXISTS(t *testing.T) {
|
||||
uid := "test_uid"
|
||||
b, err := DB.JudgeAccountEXISTS(uid)
|
||||
assert.Nil(t, err)
|
||||
fmt.Println(b)
|
||||
}
|
||||
func Test_SetAccountCode(t *testing.T) {
|
||||
uid := "test_uid"
|
||||
code := 666666
|
||||
err := DB.SetAccountCode(uid, code, 100)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
func Test_GetAccountCode(t *testing.T) {
|
||||
uid := "test_uid"
|
||||
code, err := DB.GetAccountCode(uid)
|
||||
assert.Nil(t, err)
|
||||
fmt.Println(code)
|
||||
}
|
||||
|
||||
func Test_SetFcmToken(t *testing.T) {
|
||||
uid := "test_uid"
|
||||
token := "dfnWBtOjSj-XIZnUvDlegv:APA91bG09XTtiXfpE6U7gUVMOhnKcUkNCv4WHn0UZr2clUi-tS1jEH-HiCEW8GIAhjLIGcfUJ6NIKteC023ZxDH7J0PJ5sTxoup3fHDUPLU7KgQoZS4tPyFqCbZ6bRB7esDPEnD1n_s0"
|
||||
@@ -133,10 +105,3 @@ func Test_GetFcmToken(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
fmt.Println("token is :", token)
|
||||
}
|
||||
|
||||
//func Test_GetGroupMemberList(t *testing.T) {
|
||||
// groupID := "3791742301"
|
||||
// list, err := DB.GetGroupMemberIDListFromCache(groupID)
|
||||
// assert.Nil(t, err)
|
||||
// fmt.Println(list)
|
||||
//}
|
||||
|
||||
Vendored
-32
@@ -604,35 +604,3 @@ func DelConversationFromCache(ctx context.Context, ownerUserID, conversationID s
|
||||
}()
|
||||
return utils.Wrap(db.DB.Rc.TagAsDeleted(conversationCache+ownerUserID+":"+conversationID), "DelConversationFromCache err")
|
||||
}
|
||||
|
||||
func GetExtendMsg(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, firstModifyTime int64) (extendMsg *mongoDB.ExtendMsg, err error) {
|
||||
getExtendMsg := func() (string, error) {
|
||||
extendMsg, err := db.DB.GetExtendMsg(sourceID, sessionType, clientMsgID, firstModifyTime)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "GetExtendMsgList failed")
|
||||
}
|
||||
bytes, err := json.Marshal(extendMsg)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "Marshal failed")
|
||||
}
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "sourceID", sourceID, "sessionType",
|
||||
sessionType, "clientMsgID", clientMsgID, "firstModifyTime", firstModifyTime, "extendMsg", extendMsg)
|
||||
}()
|
||||
extendMsgStr, err := db.DB.Rc.Fetch(extendMsgCache+clientMsgID, time.Second*30*60, getExtendMsg)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "Fetch failed")
|
||||
}
|
||||
extendMsg = &mongoDB.ExtendMsg{}
|
||||
err = json.Unmarshal([]byte(extendMsgStr), extendMsg)
|
||||
return extendMsg, utils.Wrap(err, "Unmarshal failed")
|
||||
}
|
||||
|
||||
func DelExtendMsg(ctx context.Context, clientMsgID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "clientMsgID", clientMsgID)
|
||||
}()
|
||||
return utils.Wrap(db.DB.Rc.TagAsDeleted(extendMsgCache+clientMsgID), "DelExtendMsg err")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user