|
- package reward
-
- import (
- "code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/redis/redis_client"
- "code.gitea.io/gitea/modules/redis/redis_key"
- "fmt"
- "math/rand"
- "time"
- )
-
- func GetSerialNoByRedis() (string, error) {
- now := time.Now()
- n, err := redis_client.IncrBy(redis_key.RewardSerialCounter(now), 1)
- if err != nil {
- log.Error("GetSerialNoByRedis RewardSerialCounter error. %v", err)
- return "", err
- }
- if n == 1 {
- redis_client.Expire(redis_key.RewardSerialCounter(now), 5*time.Minute)
- }
- return now.Format("200601021504") + fmt.Sprint(rand.Intn(10)) + fmt.Sprintf("%02d", n), nil
- }
|