Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-common
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-common
Commits
c65e3161
Commit
c65e3161
authored
Apr 03, 2023
by
chenweijian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redis key
parent
655f6c9d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
0 deletions
+50
-0
key.go
_const/rediskey/key.go
+6
-0
key_func.go
_const/rediskey/key_func.go
+12
-0
util.go
resource/redisCli/util.go
+32
-0
No files found.
_const/rediskey/key.go
0 → 100644
View file @
c65e3161
package
rediskey
const
(
// 每月首次充值返利
SlotFruitWeeklyDailyTask
=
"act:slotFruitWeeklyDailyTask:%s:%d"
// slot周活动、水果机周活动,每日任务是否领取(共用同一个key,两个活动的每日任务福利只能领取一次)2006-01:用户id
)
_const/rediskey/key_func.go
0 → 100644
View file @
c65e3161
package
rediskey
import
(
"fmt"
"git.hilo.cn/hilo-common/utils"
"time"
)
func
GetSlotFruitDailyTimes
(
userId
uint64
)
string
{
var
cstZone
=
time
.
FixedZone
(
"CST"
,
3
*
3600
)
// 东三区,沙特时间
return
fmt
.
Sprintf
(
SlotFruitWeeklyDailyTask
,
time
.
Now
()
.
In
(
cstZone
)
.
Format
(
utils
.
DATE_FORMAT
),
userId
)
}
resource/redisCli/util.go
View file @
c65e3161
...
...
@@ -3,6 +3,7 @@ package redisCli
import
(
"context"
"git.hilo.cn/hilo-common/mylogrus"
"github.com/go-redis/redis/v8"
"time"
)
...
...
@@ -33,3 +34,34 @@ func Lock(key string, expiration time.Duration) bool {
}
return
true
}
func
GetCacheInt64
(
key
string
)
(
int64
,
error
)
{
data
,
err
:=
RedisClient
.
Get
(
context
.
Background
(),
key
)
.
Int64
()
if
err
!=
nil
&&
err
!=
redis
.
Nil
{
return
0
,
err
}
return
data
,
nil
}
func
IncrBy
(
key
string
,
num
int64
)
(
int64
,
error
)
{
resNum
,
err
:=
RedisClient
.
IncrBy
(
context
.
Background
(),
key
,
num
)
.
Result
()
if
err
!=
nil
{
return
0
,
err
}
return
resNum
,
nil
}
func
IncrNumExpire
(
key
string
,
num
int64
,
expiration
time
.
Duration
)
(
int64
,
error
)
{
times
,
err
:=
IncrBy
(
key
,
num
)
if
err
!=
nil
{
return
0
,
err
}
ttl
,
err
:=
RedisClient
.
TTL
(
context
.
Background
(),
key
)
.
Result
()
if
err
!=
nil
{
return
0
,
err
}
if
ttl
==
-
1
{
RedisClient
.
Expire
(
context
.
Background
(),
key
,
expiration
)
}
return
times
,
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