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
128d01b1
Commit
128d01b1
authored
Aug 26, 2023
by
JiebinHu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加用户上麦时长Redis
parent
04b986e8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
1 deletion
+26
-1
keys.go
_const/redis_key/mic_k/keys.go
+7
-0
on_mic.go
cron/mic_cron/on_mic.go
+2
-1
mic.go
domain/model/mic_m/mic.go
+17
-0
No files found.
_const/redis_key/mic_k/keys.go
View file @
128d01b1
...
...
@@ -12,6 +12,7 @@ const (
MicDayInvite
=
MicPrefix
+
"day:invite:${userId}:${date}"
// string 自动被邀请上麦,1天一次,TTL:24H
MicGroupPowerOnMic
=
MicPrefix
+
"groupPower:${userId}:${date}"
// 家族内群上麦分钟数
MicUserOnMic
=
MicPrefix
+
"user:onMic:${tz}:${userId}:${date}"
)
func
GetUserMicDayInvite
(
userId
mysql
.
ID
)
string
{
...
...
@@ -24,3 +25,9 @@ func GetMicGroupPowerOnMic(userId uint64) string {
date
:=
time
.
Now
()
.
Format
(
"2006-01-02"
)
return
redis_key
.
ReplaceKey
(
MicGroupPowerOnMic
,
fmt
.
Sprintf
(
"%d"
,
userId
),
date
)
}
// 获取用户上麦时间
// 北京、沙特时间
func
GetUserOnMicKey
(
userId
uint64
,
tz
,
date
string
)
string
{
return
redis_key
.
ReplaceKey
(
MicUserOnMic
,
tz
,
fmt
.
Sprintf
(
"%d"
,
userId
),
date
)
}
cron/mic_cron/on_mic.go
View file @
128d01b1
...
...
@@ -64,7 +64,8 @@ func OnMicQueue() {
// 用户上麦
//if err := mic_m.IncrUserOnMic(model, onMic.UserId, onMic.Timestamp); err != nil {
if
err
:=
mic_m
.
IncrUserOnMicV2
(
model
,
onMic
.
UserId
);
err
!=
nil
{
//if err := mic_m.IncrUserOnMicV2(model, onMic.UserId); err != nil {
if
err
:=
mic_m
.
IncrUserOnMicV3
(
model
,
onMic
.
UserId
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"cron micIn IncrUserOnMic err:%v"
,
err
)
}
else
{
model
.
Log
.
Infof
(
"cron micIn IncrUserOnMic success,userId:%v,cost:%vs"
,
onMic
.
UserId
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
...
...
domain/model/mic_m/mic.go
View file @
128d01b1
...
...
@@ -7,6 +7,7 @@ import (
"git.hilo.cn/hilo-common/utils"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"hilo-group/_const/redis_key/mic_k"
"time"
)
...
...
@@ -98,6 +99,22 @@ func IncrUserOnMicV2(model *domain.Model, userId mysql.ID) error {
return
nil
}
// 增加用户上麦时长
// Redis
func
IncrUserOnMicV3
(
model
*
domain
.
Model
,
userId
mysql
.
ID
)
error
{
for
_
,
tz
:=
range
timezone_e
.
Timezones
{
day
:=
time
.
Now
()
.
In
(
timezone_e
.
TimezoneLocMap
[
tz
])
.
Format
(
"2006-01-02"
)
tzStr
:=
"bj"
if
tz
==
timezone_e
.
TimezoneKSA
{
tzStr
=
"ksa"
}
tzKey
:=
mic_k
.
GetUserOnMicKey
(
userId
,
tzStr
,
day
)
model
.
RedisCluster
.
IncrBy
(
model
,
tzKey
,
60
)
model
.
RedisCluster
.
Expire
(
model
,
tzKey
,
time
.
Hour
*
24
*
30
)
// 30天上麦时长
}
return
nil
}
// 批量获取用户上麦时长
// @return userId->seconds
func
MGetUserOnMicSeconds
(
model
*
domain
.
Model
,
day
string
,
tz
timezone_e
.
Timezone
,
userIds
[]
uint64
)
(
map
[
mysql
.
ID
]
mysql
.
Num
,
error
)
{
...
...
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