init.go 801 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package redis
  2. import (
  3. "context"
  4. "sportfitness/base/assembly/base/repository"
  5. "sportfitness/base/errors"
  6. "git.beswell.com/gframe/application"
  7. "github.com/go-redis/redis/v8"
  8. )
  9. const prefix = "bsw:sport_fitness:heart_rate"
  10. var ctx = context.Background()
  11. func Init() {
  12. err := repository.Repository.InitRedisByConfigCenter(0)
  13. if err != nil {
  14. panic(err)
  15. }
  16. }
  17. func getClient() redis.UniversalClient {
  18. return repository.Repository.GetRedisClient()
  19. }
  20. func handleTokenErr(err error) {
  21. if err != nil {
  22. if err == redis.Nil {
  23. err = application.ErrorBusinessF(errors.ErrCodeToken, "token无效")
  24. }
  25. panic(err)
  26. }
  27. }
  28. func handleErr(err error) {
  29. if err != nil {
  30. if err == redis.Nil {
  31. err = application.ErrorBusinessF(errors.ErrCodeNoRecord, "记录不存在")
  32. }
  33. panic(err)
  34. }
  35. }