From 2fa621ef418271ac0159bf911c4b5b37e313deba Mon Sep 17 00:00:00 2001 From: hujiebin Date: Mon, 7 Aug 2023 11:28:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=8615=E5=A4=A9=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E7=9A=84=E8=AE=BF=E5=AE=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/cache/group_c/enter_room.go | 4 +++- route/group_r/group_list.go | 2 ++ test/user_test.go | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/domain/cache/group_c/enter_room.go b/domain/cache/group_c/enter_room.go index e2fd116..ff8631f 100644 --- a/domain/cache/group_c/enter_room.go +++ b/domain/cache/group_c/enter_room.go @@ -66,8 +66,10 @@ func GetUserRecentRooms(model *domain.Model, userId uint64) (imGroupIds []string // 15天前访问的 func RemoveRoomVisitors(model *domain.Model, imGroupId string) { groupKey := group_k.GetUserEnterRoomGroupKey(imGroupId) - err := model.Redis.ZRemRangeByScore(model, groupKey, "-inf", fmt.Sprintf("%d", time.Now().AddDate(0, 0, -15).Unix())).Err() + n, err := model.Redis.ZRemRangeByScore(model, groupKey, "-inf", fmt.Sprintf("%d", time.Now().AddDate(0, 0, -15).Unix())).Result() if err != nil { model.Log.Errorf("RemoveRoomVisitors fail:%v", err) + } else { + model.Log.Infof("RemoveRoomVisitors key:%v,n:%v", groupKey, n) } } diff --git a/route/group_r/group_list.go b/route/group_r/group_list.go index 8a21ddf..cebe0a6 100644 --- a/route/group_r/group_list.go +++ b/route/group_r/group_list.go @@ -973,6 +973,8 @@ func GetGroupVisitors(c *gin.Context) (*mycontext.MyContext, error) { } } resp.ResponseOk(c, result) + // 清理15天之前的访客 + group_c.RemoveRoomVisitors(model, groupId) return myContext, nil } diff --git a/test/user_test.go b/test/user_test.go index 55124d9..b4310b7 100644 --- a/test/user_test.go +++ b/test/user_test.go @@ -2,6 +2,7 @@ package test import ( "git.hilo.cn/hilo-common/domain" + "hilo-group/domain/cache/group_c" "hilo-group/domain/model/user_m" "testing" ) @@ -23,3 +24,7 @@ func TestGetUserVipMap(t *testing.T) { res, err := user_m.BatchGetVips(userIds) t.Logf("%v-%v", res, err) } + +func TestRemoveRoomVisit(t *testing.T) { + group_c.RemoveRoomVisitors(domain.CreateModelNil(), "HTGS#a47478749") +} -- 2.22.0