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
278179d6
Commit
278179d6
authored
Aug 29, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/room-visit-count' into 'master'
lru批量获取房间访问人数 See merge request
!77
parents
2d0ca0c4
aef54de6
Changes
1
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 @
278179d6
...
...
@@ -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
...
...
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