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
Compare Revisions
master...feature/room-visit-count
Source
feature/room-visit-count
Select Git revision
...
Target
master
Select Git revision
Compare
Commits (1)
lru批量获取房间访问人数
· 5d59f8e5
hujiebin
authored
Aug 29, 2023
5d59f8e5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
5 deletions
+23
-5
userRoomVisit.go
domain/cache/room_c/userRoomVisit.go
+23
-5
No files found.
domain/cache/room_c/userRoomVisit.go
View file @
5d59f8e5
...
...
@@ -6,6 +6,7 @@ import (
"fmt"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/redisCli"
"github.com/bluele/gcache"
redis2
"github.com/go-redis/redis/v8"
"hilo-group/_const/redis_key"
"strconv"
...
...
@@ -76,23 +77,40 @@ func GetUserRoomVisit(userId uint64) (map[string]int64, error) {
return
result
,
nil
}
var
roomVisitCntCache
=
gcache
.
New
(
50000
)
.
LRU
()
.
Build
()
// 批量获取房间访问人数
// 带上lru
func
MGetRoomVisitCount
(
groupIds
[]
string
)
(
map
[
string
]
string
,
error
)
{
key
:=
redis_key
.
GetPrefixRoomVisitCount
()
visit
:=
make
(
map
[
string
]
string
)
if
len
(
groupIds
)
<=
0
{
return
visit
,
nil
}
res
,
err
:=
redisCli
.
GetRedis
()
.
HMGet
(
context
.
Background
(),
key
,
groupIds
...
)
.
Result
()
var
miss
[]
string
for
_
,
groupId
:=
range
groupIds
{
if
data
,
err
:=
roomVisitCntCache
.
Get
(
groupId
);
err
==
nil
{
visit
[
groupId
]
=
data
.
(
string
)
}
else
{
miss
=
append
(
miss
,
groupId
)
}
}
if
len
(
miss
)
<=
0
{
return
visit
,
nil
}
key
:=
redis_key
.
GetPrefixRoomVisitCount
()
res
,
err
:=
redisCli
.
GetRedis
()
.
HMGet
(
context
.
Background
(),
key
,
miss
...
)
.
Result
()
if
err
!=
nil
{
return
visit
,
err
}
if
len
(
res
)
!=
len
(
groupId
s
)
{
return
visit
,
errors
.
New
(
fmt
.
Sprintf
(
"MGetRoomVisitCount fail,miss match len,%v-%v"
,
len
(
res
),
len
(
groupId
s
)))
if
len
(
res
)
!=
len
(
mis
s
)
{
return
visit
,
errors
.
New
(
fmt
.
Sprintf
(
"MGetRoomVisitCount fail,miss match len,%v-%v"
,
len
(
res
),
len
(
mis
s
)))
}
for
i
,
groupId
:=
range
groupId
s
{
for
i
,
groupId
:=
range
mis
s
{
if
cnt
,
ok
:=
res
[
i
]
.
(
string
);
ok
{
visit
[
groupId
]
=
cnt
_
=
roomVisitCntCache
.
SetWithExpire
(
groupId
,
cnt
,
time
.
Minute
*
15
)
}
}
return
visit
,
nil
...
...