mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 11:05:59 +08:00
fix: read seq is written to mongo, online status redis cluster is supported (#2558)
* fix: GroupApplicationAcceptedNotification * fix: GroupApplicationAcceptedNotification * fix: NotificationUserInfoUpdate * cicd: robot automated Change * fix: component * fix: getConversationInfo * feat: cron task * feat: cron task * feat: cron task * feat: cron task * feat: cron task * fix: minio config url recognition error * update gomake version * update gomake version * fix: seq conversion bug * fix: redis pipe exec * fix: ImportFriends * fix: A large number of logs keysAndValues length is not even * feat: mark read aggregate write * feat: online status supports redis cluster * feat: online status supports redis cluster * feat: online status supports redis cluster * merge * merge * read seq is written to mongo * read seq is written to mongo --------- Co-authored-by: withchao <withchao@users.noreply.github.com>
This commit is contained in:
+19
-7
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/openimsdk/tools/log"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -66,11 +67,10 @@ func (s *userOnline) SetUserOnline(ctx context.Context, userID string, online, o
|
||||
local change = (num1 ~= num2) or (num2 ~= num3)
|
||||
if change then
|
||||
local members = redis.call("ZRANGE", key, 0, -1)
|
||||
table.insert(members, KEYS[2])
|
||||
redis.call("PUBLISH", KEYS[3], table.concat(members, ":"))
|
||||
return 1
|
||||
table.insert(members, "1")
|
||||
return members
|
||||
else
|
||||
return 0
|
||||
return {"0"}
|
||||
end
|
||||
`
|
||||
now := time.Now()
|
||||
@@ -82,12 +82,24 @@ func (s *userOnline) SetUserOnline(ctx context.Context, userID string, online, o
|
||||
for _, platformID := range online {
|
||||
argv = append(argv, platformID)
|
||||
}
|
||||
keys := []string{s.getUserOnlineKey(userID), userID, s.channelName}
|
||||
status, err := s.rdb.Eval(ctx, script, keys, argv).Result()
|
||||
keys := []string{s.getUserOnlineKey(userID)}
|
||||
platformIDs, err := s.rdb.Eval(ctx, script, keys, argv).StringSlice()
|
||||
if err != nil {
|
||||
log.ZError(ctx, "redis SetUserOnline", err, "userID", userID, "online", online, "offline", offline)
|
||||
return err
|
||||
}
|
||||
log.ZDebug(ctx, "redis SetUserOnline", "userID", userID, "online", online, "offline", offline, "status", status)
|
||||
if len(platformIDs) == 0 {
|
||||
return errs.ErrInternalServer.WrapMsg("SetUserOnline redis lua invalid return value")
|
||||
}
|
||||
if platformIDs[len(platformIDs)-1] != "0" {
|
||||
log.ZDebug(ctx, "redis SetUserOnline push", "userID", userID, "online", online, "offline", offline, "platformIDs", platformIDs[:len(platformIDs)-1])
|
||||
platformIDs[len(platformIDs)-1] = userID
|
||||
msg := strings.Join(platformIDs, ":")
|
||||
if err := s.rdb.Publish(ctx, s.channelName, msg).Err(); err != nil {
|
||||
return errs.Wrap(err)
|
||||
}
|
||||
} else {
|
||||
log.ZDebug(ctx, "redis SetUserOnline not push", "userID", userID, "online", online, "offline", offline)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user