Commit dad9dda9 authored by hujiebin's avatar hujiebin

feat:roomVisitCount退休

parent 47ef3686
......@@ -768,6 +768,7 @@ func GetUserEnterRoomKey(userId uint64) string {
return strings.Replace(userEnterRoom, "{userId}", strconv.FormatUint(userId, 10), -1)
}
// Deprecated: 用redis集群中的zset代替
func GetPrefixRoomVisitCount() string {
return roomVisitCount
}
......
......@@ -2,7 +2,6 @@ package room_c
import (
"context"
"errors"
"fmt"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/config"
......@@ -106,34 +105,6 @@ func MGetRoomVisitCount(groupIds []string) (map[string]string, error) {
visit[cast.ToString(v.Member)] = cast.ToString(v.Score)
}
return visit, nil
var miss []string
for _, groupId := range groupIds {
if data, err := roomVisitCntCache.Get(groupId); err == nil {
visit[groupId] = data.(string)
} else {
miss = append(miss, groupId)
}
}
if len(miss) <= 0 {
return visit, nil
}
key := redis_key.GetPrefixRoomVisitCount()
res, err := redisCli.GetRedis().HMGet(context.Background(), key, miss...).Result() // todo 后续用zset key的zrange拿出前面排名的
if err != nil {
return visit, err
}
if len(res) != len(miss) {
return visit, errors.New(fmt.Sprintf("MGetRoomVisitCount fail,miss match len,%v-%v", len(res), len(miss)))
}
for i, groupId := range miss {
if cnt, ok := res[i].(string); ok {
visit[groupId] = cnt
_ = roomVisitCntCache.SetWithExpire(groupId, cnt, time.Minute*15)
}
}
return visit, nil
}
func GetSetRoomVisitCount(groupId string) (int64, error) {
......@@ -141,15 +112,15 @@ func GetSetRoomVisitCount(groupId string) (int64, error) {
vc, err := redisCli.GetRedis().ZCard(context.Background(), key).Result()
// 查到合法值后,更新二级缓存
if err == nil && vc >= 0 {
if ret, err := saveRoomVisitCount(groupId, vc); err != nil {
mylogrus.MyLog.Errorf("saveRoomVisitCount %s, ret = %d, err: %v", groupId, ret, err)
if err := saveRoomVisitCount(groupId, vc); err != nil {
mylogrus.MyLog.Errorf("saveRoomVisitCount %s, err: %v", groupId, err)
}
}
return vc, err
}
func saveRoomVisitCount(groupId string, count int64) (int64, error) {
key := redis_key.GetPrefixRoomVisitCount()
func saveRoomVisitCount(groupId string, count int64) error {
//key := redis_key.GetPrefixRoomVisitCount()
zKey := redis_key.GetPrefixRoomVisitCountZset()
// zset同步存一份到redis集群
if err := redisCli.GetClusterRedis().ZAdd(context.Background(), zKey, &redis2.Z{
......@@ -157,8 +128,10 @@ func saveRoomVisitCount(groupId string, count int64) (int64, error) {
Member: groupId,
}).Err(); err != nil {
mylogrus.MyLog.Errorf("GetPrefixRoomVisitCountZset fail %s", err.Error())
return err
}
return redisCli.GetRedis().HSet(context.Background(), key, groupId, strconv.FormatInt(count, 10)).Result()
return nil
//return redisCli.GetRedis().HSet(context.Background(), key, groupId, strconv.FormatInt(count, 10)).Result()
}
func clearRoomVisit(groupId string, t time.Time) (int64, error) {
......@@ -169,9 +142,3 @@ func clearRoomVisit(groupId string, t time.Time) (int64, error) {
}
return ret, nil
}
// Deprecated: hgetall有问题
func GetAllRoomVisitCount() (map[string]string, error) {
key := redis_key.GetPrefixRoomVisitCount()
return redisCli.GetRedis().HGetAll(context.Background(), key).Result()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment