otto 9 months ago
parent
commit
6726d9bca7
  1. 2
      hotspot-clear-job-dev.yaml
  2. 54
      task/task.go

2
hotspot-clear-job-dev.yaml

@ -12,7 +12,7 @@ spec:
spec: spec:
containers: containers:
- name: hotspot-clear - name: hotspot-clear
image: 192.168.1.131:8888/job/dev/hotspot-clear:79b62d1f2cbcbfee17586c8ae7c24a76a34e97fd image: 192.168.1.131:8888/job/dev/hotspot-clear:2dfb5805e047bbfab6eee03073fc963204927cde
env: env:
- name: JM_ENVIRONMENT - name: JM_ENVIRONMENT
value: dev value: dev

54
task/task.go

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

Loading…
Cancel
Save