|
|
|
@ -51,7 +51,7 @@ func NewTask() {
|
|
|
|
|
|
|
|
|
|
func task(start, end int64) error { |
|
|
|
|
redisClient := NewRedis() |
|
|
|
|
result, err := redisClient.ZRange(context.Background(), hotKey, start, end).Result() |
|
|
|
|
result, err := redisClient.ZRangeWithScores(context.Background(), hotKey, start, end).Result() |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
@ -62,32 +62,36 @@ func task(start, end int64) error {
|
|
|
|
|
members []redis.Z |
|
|
|
|
ids []int64 |
|
|
|
|
) |
|
|
|
|
for _, id := range result { |
|
|
|
|
i, _ := strconv.Atoi(id) |
|
|
|
|
if i != 0 { |
|
|
|
|
ids = append(ids, int64(i)) |
|
|
|
|
} |
|
|
|
|
members = append(members, redis.Z{ |
|
|
|
|
Member: id, |
|
|
|
|
Score: 0, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
err = redisClient.ZAdd(context.Background(), hotKey, members...).Err() |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
for _, val := range result { |
|
|
|
|
|
|
|
|
|
roomClient, roomClientClose, err := client.GetRoomClientV2(context.Background()) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
if val.Score > 0 { |
|
|
|
|
id, _ := strconv.Atoi(val.Member.(string)) |
|
|
|
|
if id != 0 { |
|
|
|
|
ids = append(ids, int64(id)) |
|
|
|
|
members = append(members, redis.Z{ |
|
|
|
|
Member: id, |
|
|
|
|
Score: 0, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
defer roomClientClose() |
|
|
|
|
_, err = roomClient.IncrRoomHotspot(context.Background(), &v2.IncrRoomHotspotReq{ |
|
|
|
|
RoomIdList: ids, |
|
|
|
|
HotValue: 0, |
|
|
|
|
}) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
if len(ids) != 0 { |
|
|
|
|
err = redisClient.ZAdd(context.Background(), hotKey, members...).Err() |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
roomClient, roomClientClose, err := client.GetRoomClientV2(context.Background()) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
defer func() { _ = roomClientClose() }() |
|
|
|
|
_, err = roomClient.IncrRoomHotspot(context.Background(), &v2.IncrRoomHotspotReq{ |
|
|
|
|
RoomIdList: ids, |
|
|
|
|
HotValue: 0, |
|
|
|
|
}) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 递增查询
|
|
|
|
|
start = end + 1 |
|
|
|
|