From 6726d9bca7695ff14eb2acc003dc92c9449fdd72 Mon Sep 17 00:00:00 2001 From: otto <965391514@qq.com> Date: Sun, 7 Apr 2024 11:54:22 +0800 Subject: [PATCH] up --- hotspot-clear-job-dev.yaml | 2 +- task/task.go | 54 ++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/hotspot-clear-job-dev.yaml b/hotspot-clear-job-dev.yaml index 4460459..e338811 100644 --- a/hotspot-clear-job-dev.yaml +++ b/hotspot-clear-job-dev.yaml @@ -12,7 +12,7 @@ spec: spec: containers: - 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: - name: JM_ENVIRONMENT value: dev diff --git a/task/task.go b/task/task.go index 818f09d..dcefe38 100644 --- a/task/task.go +++ b/task/task.go @@ -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