aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/lua/ratelimit.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2022-12-24 21:57:13 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2022-12-24 21:57:13 +0000
commit37bd2212f625089a81c7518e8f0b033c056a722c (patch)
tree651eb96a8bdfb2a56e204010533ed63ee9a83b08 /src/plugins/lua/ratelimit.lua
parent1d60483e9f9ea04a22df9264d92dad6872255d1d (diff)
downloadrspamd-37bd2212f625089a81c7518e8f0b033c056a722c.tar.gz
rspamd-37bd2212f625089a81c7518e8f0b033c056a722c.zip
[Minor] Ratelimit: Further penging field adjustments
Diffstat (limited to 'src/plugins/lua/ratelimit.lua')
-rw-r--r--src/plugins/lua/ratelimit.lua10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua
index 9975f17a3..d61e3990f 100644
--- a/src/plugins/lua/ratelimit.lua
+++ b/src/plugins/lua/ratelimit.lua
@@ -192,12 +192,12 @@ local bucket_update_script = [[
end
end
- local burst = tonumber(redis.call('HGET', KEYS[1], 'b'))
- if burst < 0 then burst = 0 end
+ local burst,pending = unpack(redis.call('HMGET', KEYS[1], '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
- redis.call('HINCRBYFLOAT', KEYS[1], 'b', nrcpt)
- redis.call('HINCRBY', KEYS[1], 'p', -(nrcpt))
- redis.call('HSET', KEYS[1], 'l', KEYS[2])
+ redis.call('HMSET', KEYS[1], 'b', tostring(burst), 'p', tostring(pending), 'l', KEYS[2])
redis.call('EXPIRE', KEYS[1], KEYS[7])
return {tostring(burst), tostring(dr), tostring(db)}