You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

serial.go 611 B

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
1234567891011121314151617181920212223
  1. package reward
  2. import (
  3. "code.gitea.io/gitea/modules/log"
  4. "code.gitea.io/gitea/modules/redis/redis_client"
  5. "code.gitea.io/gitea/modules/redis/redis_key"
  6. "fmt"
  7. "math/rand"
  8. "time"
  9. )
  10. func GetSerialNoByRedis() (string, error) {
  11. now := time.Now()
  12. n, err := redis_client.IncrBy(redis_key.RewardSerialCounter(now), 1)
  13. if err != nil {
  14. log.Error("GetSerialNoByRedis RewardSerialCounter error. %v", err)
  15. return "", err
  16. }
  17. if n == 1 {
  18. redis_client.Expire(redis_key.RewardSerialCounter(now), 5*time.Minute)
  19. }
  20. return now.Format("200601021504") + fmt.Sprint(rand.Intn(10)) + fmt.Sprintf("%02d", n), nil
  21. }