Commit 2a0e1ab9 by tbphp

fix: Redis limit ignoring max eq 0

parent 52d5d495
...@@ -93,6 +93,7 @@ func redisRateLimitHandler(duration int64, totalMaxCount, successMaxCount int) g ...@@ -93,6 +93,7 @@ func redisRateLimitHandler(duration int64, totalMaxCount, successMaxCount int) g
} }
//2.检查总请求数限制并记录总请求(当totalMaxCount为0时会自动跳过,使用令牌桶限流器 //2.检查总请求数限制并记录总请求(当totalMaxCount为0时会自动跳过,使用令牌桶限流器
if totalMaxCount > 0 {
totalKey := fmt.Sprintf("rateLimit:%s", userId) totalKey := fmt.Sprintf("rateLimit:%s", userId)
// 初始化 // 初始化
tb := limiter.New(ctx, rdb) tb := limiter.New(ctx, rdb)
...@@ -113,6 +114,7 @@ func redisRateLimitHandler(duration int64, totalMaxCount, successMaxCount int) g ...@@ -113,6 +114,7 @@ func redisRateLimitHandler(duration int64, totalMaxCount, successMaxCount int) g
if !allowed { if !allowed {
abortWithOpenAiMessage(c, http.StatusTooManyRequests, fmt.Sprintf("您已达到总请求数限制:%d分钟内最多请求%d次,包括失败次数,请检查您的请求是否正确", setting.ModelRequestRateLimitDurationMinutes, totalMaxCount)) abortWithOpenAiMessage(c, http.StatusTooManyRequests, fmt.Sprintf("您已达到总请求数限制:%d分钟内最多请求%d次,包括失败次数,请检查您的请求是否正确", setting.ModelRequestRateLimitDurationMinutes, totalMaxCount))
} }
}
// 4. 处理请求 // 4. 处理请求
c.Next() c.Next()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment