39 lines
631 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}