Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-group
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-group
Commits
b6f697a4
Commit
b6f697a4
authored
Aug 29, 2023
by
iamhujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zset同步存一份到redis集群
parent
97801bdd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
3 deletions
+19
-3
redisPrefix.go
_const/redis_key/redisPrefix.go
+7
-0
userRoomVisit.go
domain/cache/room_c/userRoomVisit.go
+12
-3
No files found.
_const/redis_key/redisPrefix.go
View file @
b6f697a4
...
...
@@ -249,6 +249,9 @@ const groupInUserDuration = "group_in_user_duration_{groupUuid}"
// 15天内进入房间的人数
const
roomVisitCount
=
"room_visit_count"
// 15天内进入房间的人数 member groupId score 麦位有人的数量
const
roomVisitCountZSet
=
"room_visit_count_zset"
// 用户进入过的房间及时间
const
userEnterRoom
=
"enter_room_{userId}"
...
...
@@ -769,6 +772,10 @@ func GetPrefixRoomVisitCount() string {
return
roomVisitCount
}
func
GetPrefixRoomVisitCountZset
()
string
{
return
roomVisitCountZSet
}
func
GetPrefixSupportLevel
(
date
string
)
string
{
return
strings
.
Replace
(
supportLevel
,
"{date}"
,
date
,
-
1
)
}
...
...
domain/cache/room_c/userRoomVisit.go
View file @
b6f697a4
...
...
@@ -100,7 +100,7 @@ func MGetRoomVisitCount(groupIds []string) (map[string]string, error) {
}
key
:=
redis_key
.
GetPrefixRoomVisitCount
()
res
,
err
:=
redisCli
.
GetRedis
()
.
HMGet
(
context
.
Background
(),
key
,
miss
...
)
.
Result
()
res
,
err
:=
redisCli
.
GetRedis
()
.
HMGet
(
context
.
Background
(),
key
,
miss
...
)
.
Result
()
// todo 后续用zset key的zrange拿出前面排名的
if
err
!=
nil
{
return
visit
,
err
}
...
...
@@ -121,14 +121,23 @@ func GetSetRoomVisitCount(groupId string) (int64, error) {
vc
,
err
:=
redisCli
.
GetRedis
()
.
ZCard
(
context
.
Background
(),
key
)
.
Result
()
// 查到合法值后,更新二级缓存
if
err
==
nil
&&
vc
>=
0
{
ret
,
err
:=
saveRoomVisitCount
(
groupId
,
vc
)
mylogrus
.
MyLog
.
Infof
(
"saveRoomVisitCount %s, ret = %d, err: %v"
,
groupId
,
ret
,
err
)
if
ret
,
err
:=
saveRoomVisitCount
(
groupId
,
vc
);
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"saveRoomVisitCount %s, ret = %d, err: %v"
,
groupId
,
ret
,
err
)
}
}
return
vc
,
err
}
func
saveRoomVisitCount
(
groupId
string
,
count
int64
)
(
int64
,
error
)
{
key
:=
redis_key
.
GetPrefixRoomVisitCount
()
zKey
:=
redis_key
.
GetPrefixRoomVisitCountZset
()
// zset同步存一份到redis集群
if
err
:=
redisCli
.
GetClusterRedis
()
.
ZAdd
(
context
.
Background
(),
zKey
,
&
redis2
.
Z
{
Score
:
float64
(
count
),
Member
:
groupId
,
})
.
Err
();
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"GetPrefixRoomVisitCountZset fail %s"
,
err
.
Error
())
}
return
redisCli
.
GetRedis
()
.
HSet
(
context
.
Background
(),
key
,
groupId
,
strconv
.
FormatInt
(
count
,
10
))
.
Result
()
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment