ZADD只保存10000个排行数据
This commit is contained in:
parent
042f6339d5
commit
8c90d018c2
@ -194,6 +194,20 @@ func RedisZAdd(key string, member string, score float64) {
|
||||
err := RdbWrite.ZAdd(ctx, key, redis.Z{Score: score, Member: member}).Err()
|
||||
if err != nil {
|
||||
log.Debug("redis zadd failed, err:%v\n", err)
|
||||
return
|
||||
}
|
||||
const maxRankSize int64 = 10000
|
||||
count, err := RdbWrite.ZCard(ctx, key).Result()
|
||||
if err != nil {
|
||||
log.Debug("redis zcard failed, err:%v\n", err)
|
||||
return
|
||||
}
|
||||
if count > maxRankSize {
|
||||
removeCount := count - maxRankSize
|
||||
err = RdbWrite.ZRemRangeByRank(ctx, key, 0, removeCount-1).Err()
|
||||
if err != nil {
|
||||
log.Debug("redis zremrangebyrank failed, err:%v\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -281,3 +281,7 @@ func TestChampionShipCreateRobot(t *testing.T) {
|
||||
robot := game.CreateRobot(1.0, 1)
|
||||
fmt.Printf("Created Robot: %v\n", robot)
|
||||
}
|
||||
|
||||
func TestRedisZset(t *testing.T) {
|
||||
db.RedisZAdd("rank_user", "100001", 100)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user