Commit c65e3161 authored by chenweijian's avatar chenweijian

redis key

parent 655f6c9d
package rediskey
const (
// 每月首次充值返利
SlotFruitWeeklyDailyTask = "act:slotFruitWeeklyDailyTask:%s:%d" // slot周活动、水果机周活动,每日任务是否领取(共用同一个key,两个活动的每日任务福利只能领取一次)2006-01:用户id
)
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)
}
...@@ -3,6 +3,7 @@ package redisCli ...@@ -3,6 +3,7 @@ package redisCli
import ( import (
"context" "context"
"git.hilo.cn/hilo-common/mylogrus" "git.hilo.cn/hilo-common/mylogrus"
"github.com/go-redis/redis/v8"
"time" "time"
) )
...@@ -33,3 +34,34 @@ func Lock(key string, expiration time.Duration) bool { ...@@ -33,3 +34,34 @@ func Lock(key string, expiration time.Duration) bool {
} }
return true 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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment