From 8658223c61de98aae7e61c3047ecb7690607f33d Mon Sep 17 00:00:00 2001 From: icey-yu <1186114839@qq.com> Date: Mon, 9 Sep 2024 18:00:40 +0800 Subject: [PATCH] fix: userIDs --- pkg/common/storage/cache/cachekey/online.go | 9 ++++++++- pkg/common/storage/cache/redis/online.go | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/common/storage/cache/cachekey/online.go b/pkg/common/storage/cache/cachekey/online.go index 164e5f2f4..40f09cb5a 100644 --- a/pkg/common/storage/cache/cachekey/online.go +++ b/pkg/common/storage/cache/cachekey/online.go @@ -1,6 +1,9 @@ package cachekey -import "time" +import ( + "strings" + "time" +) const ( OnlineKey = "ONLINE:" @@ -11,3 +14,7 @@ const ( 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/redis/online.go b/pkg/common/storage/cache/redis/online.go index 8b2efa160..b6c90264e 100644 --- a/pkg/common/storage/cache/redis/online.go +++ b/pkg/common/storage/cache/redis/online.go @@ -60,6 +60,7 @@ func (s *userOnline) GetAllOnlineUsers(ctx context.Context, cursor uint64) (map[ } for _, key := range keys { + userID := cachekey.GetOnlineKeyUserID(key) strValues, err := s.rdb.ZRange(ctx, key, 0, -1).Result() if err != nil { return nil, 0, err @@ -74,7 +75,7 @@ func (s *userOnline) GetAllOnlineUsers(ctx context.Context, cursor uint64) (map[ values = append(values, int32(intValue)) } - result[key] = values + result[userID] = values } return result, nextCursor, nil