crm_config_cache.go 745 B

1234567891011121314151617181920212223242526272829303132333435
  1. package cache
  2. import (
  3. "fmt"
  4. "hongze/hz_crm_api/models/company"
  5. "hongze/hz_crm_api/utils"
  6. "strconv"
  7. "time"
  8. )
  9. func GetIntervalFromCrmConfig(key string) int {
  10. //redis 查询key
  11. sIntervals := utils.Rc.Get(key)
  12. var interval int
  13. var err error
  14. if sIntervals == nil {
  15. //redis没查到,去数据库查
  16. interval, err = company.GetConfigValueByCode(key)
  17. if err != nil {
  18. fmt.Println("GetConfigValueByCode Err:" + err.Error())
  19. }
  20. //插入redis
  21. if !utils.Rc.SetNX(key, interval, 2*time.Hour) {
  22. fmt.Println("setNX Err")
  23. }
  24. return interval
  25. } else {
  26. intervals := fmt.Sprintf("%s", sIntervals)
  27. interval, err = strconv.Atoi(intervals)
  28. if err != nil {
  29. fmt.Println("strconv err:", err.Error())
  30. }
  31. return interval
  32. }
  33. }