Skip to content

Commit

Permalink
feat: 滑动窗口脚本调整#1539
Browse files Browse the repository at this point in the history
  • Loading branch information
zacYL committed Oct 28, 2024
1 parent ca2ab03 commit 5cbd93c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ abstract class AbstractRateLimiterService(
}

if (resLimitInfo == null) {
logger.info("no rule in ${this.javaClass.simpleName} for request ${request.requestURI}")
return null
}
return resLimitInfo
Expand Down Expand Up @@ -365,7 +364,13 @@ abstract class AbstractRateLimiterService(
}

private fun clearLimiterCache() {
rateLimiterCache.forEach { it.value.removeCacheLimit(it.key) }
rateLimiterCache.forEach {
try {
it.value.removeCacheLimit(it.key)
} catch (e: Exception) {
logger.warn("clear limiter cacher error: ${e.cause}, ${e.message}")
}
}
rateLimiterCache.clear()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ allowed_num = 1
-- 生成令牌,并返回生成的令牌数量
local tokens = {}
for i = 1, count do
table.insert(tokens, now_sec)
table.insert(tokens, random..i)
redis.call('zadd', key, now_sec, random..i)
end
redis.call('zadd', key, unpack(tokens))
redis.call('expire', key, interval)
return { allowed_num, remaining }

0 comments on commit 5cbd93c

Please sign in to comment.