package cache import ( "fmt" "hongze/hz_crm_api/models/company" "hongze/hz_crm_api/utils" "strconv" "time" ) func GetIntervalFromCrmConfig(key string) int { //redis 查询key sIntervals := utils.Rc.Get(key) var interval int var err error if sIntervals == nil { //redis没查到,去数据库查 interval, err = company.GetConfigValueByCode(key) if err != nil { fmt.Println("GetConfigValueByCode Err:" + err.Error()) } //插入redis if !utils.Rc.SetNX(key, interval, 2*time.Hour) { fmt.Println("setNX Err") } return interval } else { intervals := fmt.Sprintf("%s", sIntervals) interval, err = strconv.Atoi(intervals) if err != nil { fmt.Println("strconv err:", err.Error()) } return interval } }