Commit 77fa9ad1 authored by iamhujiebin's avatar iamhujiebin

3个月 / 15天

parent ace0492e
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
const ( const (
UserEnterRoomPrefix = "uer:" UserEnterRoomPrefix = "uer:"
UserEnterRoomUserKey = UserEnterRoomPrefix + "u:${user_id}" UserEnterRoomUserKey = UserEnterRoomPrefix + "u:${user_id}"
UserEnterRoomGroupKey = UserEnterRoomPrefix + "g:${user_id}" UserEnterRoomGroupKey = UserEnterRoomPrefix + "g:${group_id}"
) )
func GetUserEnterRoomUserKey(userId uint64) string { func GetUserEnterRoomUserKey(userId uint64) string {
......
...@@ -28,6 +28,7 @@ func ZAddUserEnterRoom(model *domain.Model, userId uint64, imGroupId string) { ...@@ -28,6 +28,7 @@ func ZAddUserEnterRoom(model *domain.Model, userId uint64, imGroupId string) {
} }
// 获取最近房间访客 // 获取最近房间访客
// 15天
func GetLastRoomVisitors(model *domain.Model, imGroupId string) (userIds []uint64) { func GetLastRoomVisitors(model *domain.Model, imGroupId string) (userIds []uint64) {
groupKey := group_k.GetUserEnterRoomGroupKey(imGroupId) groupKey := group_k.GetUserEnterRoomGroupKey(imGroupId)
res, err := model.Redis.ZRangeByScore(model, groupKey, &redis.ZRangeBy{ res, err := model.Redis.ZRangeByScore(model, groupKey, &redis.ZRangeBy{
...@@ -47,11 +48,12 @@ func GetLastRoomVisitors(model *domain.Model, imGroupId string) (userIds []uint6 ...@@ -47,11 +48,12 @@ func GetLastRoomVisitors(model *domain.Model, imGroupId string) (userIds []uint6
} }
// 获取最近进入的房间 // 获取最近进入的房间
// 3个月
func GetUserRecentRooms(model *domain.Model, userId uint64) (imGroupIds []string) { func GetUserRecentRooms(model *domain.Model, userId uint64) (imGroupIds []string) {
userKey := group_k.GetUserEnterRoomUserKey(userId) userKey := group_k.GetUserEnterRoomUserKey(userId)
var err error var err error
imGroupIds, err = model.Redis.ZRangeByScore(model, userKey, &redis.ZRangeBy{ imGroupIds, err = model.Redis.ZRangeByScore(model, userKey, &redis.ZRangeBy{
Min: fmt.Sprintf("%d", time.Now().AddDate(0, 0, -15).Unix()), Min: fmt.Sprintf("%d", time.Now().AddDate(0, -3, 0).Unix()),
Max: "+inf", Max: "+inf",
}).Result() }).Result()
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment