|
|
|
@ -17,6 +17,7 @@ package cache
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"github.com/OpenIMSDK/protocol/constant"
|
|
|
|
|
"hash/crc32"
|
|
|
|
|
"strconv"
|
|
|
|
|
"time"
|
|
|
|
@ -37,6 +38,7 @@ const (
|
|
|
|
|
olineStatusKey = "ONLINE_STATUS:"
|
|
|
|
|
userOlineStatusExpireTime = time.Second * 60 * 60 * 24
|
|
|
|
|
statusMod = 501
|
|
|
|
|
platformID = "_PlatformID_"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type UserCache interface {
|
|
|
|
@ -92,6 +94,10 @@ func (u *UserCacheRedis) getUserGlobalRecvMsgOptKey(userID string) string {
|
|
|
|
|
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) {
|
|
|
|
|
return getCache(
|
|
|
|
|
ctx,
|
|
|
|
@ -178,7 +184,7 @@ func (u *UserCacheRedis) GetUserStatus(ctx context.Context, userIDs []string) ([
|
|
|
|
|
// key or field does not exist
|
|
|
|
|
res = append(res, &user.OnlineStatus{
|
|
|
|
|
UserID: userID,
|
|
|
|
|
Status: 0,
|
|
|
|
|
Status: constant.Offline,
|
|
|
|
|
PlatformID: -1,
|
|
|
|
|
})
|
|
|
|
|
continue
|
|
|
|
@ -211,6 +217,8 @@ func (u *UserCacheRedis) SetUserStatus(ctx context.Context, list []*user.OnlineS
|
|
|
|
|
if err != nil {
|
|
|
|
|
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()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errs.Wrap(err)
|
|
|
|
|