package consumer import ( "context" "hepa-calc-api/global" "strconv" "time" ) // 检测执行次数 func checkHandleNumber(key string) bool { c := context.Background() res, _ := global.Redis.Get(c, key).Result() if res == "" { // 添加缓存 _, _ = global.Redis.Set(c, key, 1, (60*60*2)*time.Second).Result() return true } // string转int handleNum, err := strconv.Atoi(res) if err != nil { return false } if handleNum > 3 { // 加入短信队列,通知管理员 // 返回false,删除掉缓存 global.Redis.Del(c, key) return false } // 增加1次 global.Redis.Incr(c, key) return true }