aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/redis_scripts/ratelimit_update.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lualib/redis_scripts/ratelimit_update.lua')
-rw-r--r--lualib/redis_scripts/ratelimit_update.lua20
1 files changed, 14 insertions, 6 deletions
diff --git a/lualib/redis_scripts/ratelimit_update.lua b/lualib/redis_scripts/ratelimit_update.lua
index f08a250ea..caee8fb31 100644
--- a/lualib/redis_scripts/ratelimit_update.lua
+++ b/lualib/redis_scripts/ratelimit_update.lua
@@ -19,7 +19,7 @@ if not last then
-- 2. Initialize a new bucket if the last hit time is not found (must not happen)
redis.call('HMSET', prefix, 'l', tostring(now), 'b', tostring(nrcpt), 'dr', '10000', 'db', '10000', 'p', '0')
redis.call('EXPIRE', prefix, KEYS[7])
- return {1, 1, 1}
+ return { 1, 1, 1 }
end
-- 3. Update the dynamic rate multiplier based on input parameters
@@ -72,14 +72,22 @@ if max_db > 1 then
end
-- 5. Update the burst and pending values based on the number of recipients (requests)
-local burst,pending = unpack(redis.call('HMGET', prefix, 'b', 'p'))
-burst,pending = tonumber(burst or '0'),tonumber(pending or '0')
-if burst < 0 then burst = nrcpt else burst = burst + nrcpt end
-if pending < nrcpt then pending = 0 else pending = pending - nrcpt end
+local burst, pending = unpack(redis.call('HMGET', prefix, 'b', 'p'))
+burst, pending = tonumber(burst or '0'), tonumber(pending or '0')
+if burst < 0 then
+ burst = nrcpt
+else
+ burst = burst + nrcpt
+end
+if pending < nrcpt then
+ pending = 0
+else
+ pending = pending - nrcpt
+end
-- 6. Set the updated values back to Redis and update the expiration time for the bucket
redis.call('HMSET', prefix, 'b', tostring(burst), 'p', tostring(pending), 'l', KEYS[2])
redis.call('EXPIRE', prefix, KEYS[7])
-- 7. Return the updated burst value, dynamic rate multiplier, and dynamic burst multiplier
-return {tostring(burst), tostring(dr), tostring(db)} \ No newline at end of file
+return { tostring(burst), tostring(dr), tostring(db) } \ No newline at end of file