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
d3164265
Commit
d3164265
authored
Sep 01, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into test
parents
e8452c4e
dad9dda9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
40 deletions
+8
-40
redisPrefix.go
_const/redis_key/redisPrefix.go
+1
-0
userRoomVisit.go
domain/cache/room_c/userRoomVisit.go
+7
-40
No files found.
_const/redis_key/redisPrefix.go
View file @
d3164265
...
...
@@ -768,6 +768,7 @@ func GetUserEnterRoomKey(userId uint64) string {
return
strings
.
Replace
(
userEnterRoom
,
"{userId}"
,
strconv
.
FormatUint
(
userId
,
10
),
-
1
)
}
// Deprecated: 用redis集群中的zset代替
func
GetPrefixRoomVisitCount
()
string
{
return
roomVisitCount
}
...
...
domain/cache/room_c/userRoomVisit.go
View file @
d3164265
...
...
@@ -2,7 +2,6 @@ package room_c
import
(
"context"
"errors"
"fmt"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/config"
...
...
@@ -106,34 +105,6 @@ func MGetRoomVisitCount(groupIds []string) (map[string]string, error) {
visit
[
cast
.
ToString
(
v
.
Member
)]
=
cast
.
ToString
(
v
.
Score
)
}
return
visit
,
nil
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
()
// todo 后续用zset key的zrange拿出前面排名的
if
err
!=
nil
{
return
visit
,
err
}
if
len
(
res
)
!=
len
(
miss
)
{
return
visit
,
errors
.
New
(
fmt
.
Sprintf
(
"MGetRoomVisitCount fail,miss match len,%v-%v"
,
len
(
res
),
len
(
miss
)))
}
for
i
,
groupId
:=
range
miss
{
if
cnt
,
ok
:=
res
[
i
]
.
(
string
);
ok
{
visit
[
groupId
]
=
cnt
_
=
roomVisitCntCache
.
SetWithExpire
(
groupId
,
cnt
,
time
.
Minute
*
15
)
}
}
return
visit
,
nil
}
func
GetSetRoomVisitCount
(
groupId
string
)
(
int64
,
error
)
{
...
...
@@ -141,15 +112,15 @@ func GetSetRoomVisitCount(groupId string) (int64, error) {
vc
,
err
:=
redisCli
.
GetRedis
()
.
ZCard
(
context
.
Background
(),
key
)
.
Result
()
// 查到合法值后,更新二级缓存
if
err
==
nil
&&
vc
>=
0
{
if
ret
,
err
:=
saveRoomVisitCount
(
groupId
,
vc
);
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"saveRoomVisitCount %s,
ret = %d, err: %v"
,
groupId
,
ret
,
err
)
if
err
:=
saveRoomVisitCount
(
groupId
,
vc
);
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"saveRoomVisitCount %s,
err: %v"
,
groupId
,
err
)
}
}
return
vc
,
err
}
func
saveRoomVisitCount
(
groupId
string
,
count
int64
)
(
int64
,
error
)
{
key
:=
redis_key
.
GetPrefixRoomVisitCount
()
func
saveRoomVisitCount
(
groupId
string
,
count
int64
)
error
{
//
key := redis_key.GetPrefixRoomVisitCount()
zKey
:=
redis_key
.
GetPrefixRoomVisitCountZset
()
// zset同步存一份到redis集群
if
err
:=
redisCli
.
GetClusterRedis
()
.
ZAdd
(
context
.
Background
(),
zKey
,
&
redis2
.
Z
{
...
...
@@ -157,8 +128,10 @@ func saveRoomVisitCount(groupId string, count int64) (int64, error) {
Member
:
groupId
,
})
.
Err
();
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"GetPrefixRoomVisitCountZset fail %s"
,
err
.
Error
())
return
err
}
return
redisCli
.
GetRedis
()
.
HSet
(
context
.
Background
(),
key
,
groupId
,
strconv
.
FormatInt
(
count
,
10
))
.
Result
()
return
nil
//return redisCli.GetRedis().HSet(context.Background(), key, groupId, strconv.FormatInt(count, 10)).Result()
}
func
clearRoomVisit
(
groupId
string
,
t
time
.
Time
)
(
int64
,
error
)
{
...
...
@@ -169,9 +142,3 @@ func clearRoomVisit(groupId string, t time.Time) (int64, error) {
}
return
ret
,
nil
}
// Deprecated: hgetall有问题
func
GetAllRoomVisitCount
()
(
map
[
string
]
string
,
error
)
{
key
:=
redis_key
.
GetPrefixRoomVisitCount
()
return
redisCli
.
GetRedis
()
.
HGetAll
(
context
.
Background
(),
key
)
.
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