Fixed - RRateLimiter incorrect rate count in the event of an attempt to exceed the limit. #5751

pull/6080/head
Nikita Koksharov 6 months ago
parent 53cef30bbf
commit 947cbfbd9b

@ -185,7 +185,7 @@ public class RedissonRateLimiter extends RedissonExpirable implements RRateLimit
+ "permitsName = KEYS[5];" + "permitsName = KEYS[5];"
+ "end;" + "end;"
+ "assert(tonumber(rate) >= tonumber(ARGV[1]), 'Requested permits amount could not exceed defined rate'); " + "assert(tonumber(rate) >= tonumber(ARGV[1]), 'Requested permits amount cannot exceed defined rate'); "
+ "local currentValue = redis.call('get', valueName); " + "local currentValue = redis.call('get', valueName); "
+ "local res;" + "local res;"
@ -200,7 +200,13 @@ public class RedissonRateLimiter extends RedissonExpirable implements RRateLimit
+ "if released > 0 then " + "if released > 0 then "
+ "redis.call('zremrangebyscore', permitsName, 0, tonumber(ARGV[2]) - interval); " + "redis.call('zremrangebyscore', permitsName, 0, tonumber(ARGV[2]) - interval); "
+ "if tonumber(currentValue) + released > tonumber(rate) then " + "if tonumber(currentValue) + released > tonumber(rate) then "
+ "currentValue = tonumber(rate) - redis.call('zcard', permitsName); " + "local values = redis.call('zrange', permitsName, 0, -1); "
+ "local used = 0; "
+ "for i, v in ipairs(values) do "
+ "local random, permits = struct.unpack('Bc0I', v);"
+ "used = used + permits;"
+ "end; "
+ "currentValue = tonumber(rate) - used; "
+ "else " + "else "
+ "currentValue = tonumber(currentValue) + released; " + "currentValue = tonumber(currentValue) + released; "
+ "end; " + "end; "

Loading…
Cancel
Save