mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-17 03:27:02 +08:00
test
This commit is contained in:
parent
03906a89cd
commit
f281c3dfd7
10
pkg/common/db/cache/user.go
vendored
10
pkg/common/db/cache/user.go
vendored
@ -17,6 +17,7 @@ package cache
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/OpenIMSDK/protocol/constant"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@ -37,6 +38,7 @@ const (
|
|||||||
olineStatusKey = "ONLINE_STATUS:"
|
olineStatusKey = "ONLINE_STATUS:"
|
||||||
userOlineStatusExpireTime = time.Second * 60 * 60 * 24
|
userOlineStatusExpireTime = time.Second * 60 * 60 * 24
|
||||||
statusMod = 501
|
statusMod = 501
|
||||||
|
platformID = "_PlatformID_"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserCache interface {
|
type UserCache interface {
|
||||||
@ -92,6 +94,10 @@ func (u *UserCacheRedis) getUserGlobalRecvMsgOptKey(userID string) string {
|
|||||||
return userGlobalRecvMsgOptKey + userID
|
return userGlobalRecvMsgOptKey + userID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *UserCacheRedis) getUserStatusHashKey(userID string, Id int32) string {
|
||||||
|
return userID + platformID + string(Id)
|
||||||
|
}
|
||||||
|
|
||||||
func (u *UserCacheRedis) GetUserInfo(ctx context.Context, userID string) (userInfo *relationTb.UserModel, err error) {
|
func (u *UserCacheRedis) GetUserInfo(ctx context.Context, userID string) (userInfo *relationTb.UserModel, err error) {
|
||||||
return getCache(
|
return getCache(
|
||||||
ctx,
|
ctx,
|
||||||
@ -178,7 +184,7 @@ func (u *UserCacheRedis) GetUserStatus(ctx context.Context, userIDs []string) ([
|
|||||||
// key or field does not exist
|
// key or field does not exist
|
||||||
res = append(res, &user.OnlineStatus{
|
res = append(res, &user.OnlineStatus{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
Status: 0,
|
Status: constant.Offline,
|
||||||
PlatformID: -1,
|
PlatformID: -1,
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
@ -211,6 +217,8 @@ func (u *UserCacheRedis) SetUserStatus(ctx context.Context, list []*user.OnlineS
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.Wrap(err)
|
return errs.Wrap(err)
|
||||||
}
|
}
|
||||||
|
//TODO 把平台号加到key上面保持key唯一
|
||||||
|
hashKey := u.getUserStatusHashKey(status.UserID, status.PlatformID)
|
||||||
_, err = u.rdb.HSet(ctx, key, status.UserID, string(jsonData)).Result()
|
_, err = u.rdb.HSet(ctx, key, status.UserID, string(jsonData)).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.Wrap(err)
|
return errs.Wrap(err)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user