New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
剩余可用令牌数计算错误 #5751
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
在tryAcquireAsync方法的lua脚本中, 计算当前可用的令牌数时
当tonumber(currentValue) + released > tonumber(rate)时,
那么 currentValue = tonumber(rate) - redis.call("zcard", permitsName)
这里减去的数量为什么是permitsName的元素的个数, 而不是已使用的令牌数相加
比如像下面这样计算是不是会更准确一些
if tonumber(currentValue) + released > tonumber(rate) then
// 统计当前已经使用的令牌数量
local usedValues = redis.call("zrange", permitsName, 0, -1)
local used = 0
for i, v in ipairs(usedValues) do
local random, permits = struct.unpack("Bc0I", v)
used = used + permits
end
// 可用令牌数=rate-已经使用的令牌数量
currentValue = tonumber(rate) -used
3.27.2
The text was updated successfully, but these errors were encountered: