diff options
author | Andrew Lewis <nerf@judo.za.org> | 2017-08-30 13:42:12 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2017-08-30 13:42:12 +0200 |
commit | 7ea56e5b36a5c4d21c23d8f2f5b2f3da7694deb7 (patch) | |
tree | c2bcad85e8eb8232c51457718e8e93c8e39a1601 | |
parent | 8c045e1416977693b31c9ed086fcbb3b3b71aa8d (diff) | |
download | rspamd-7ea56e5b36a5c4d21c23d8f2f5b2f3da7694deb7.tar.gz rspamd-7ea56e5b36a5c4d21c23d8f2f5b2f3da7694deb7.zip |
[Minor] Ratelimit: support use of redis HSET for limits
-rw-r--r-- | .luacheckrc | 4 | ||||
-rw-r--r-- | lualib/lua_util.lua | 5 | ||||
-rw-r--r-- | src/plugins/lua/ratelimit.lua | 17 |
3 files changed, 24 insertions, 2 deletions
diff --git a/.luacheckrc b/.luacheckrc index 07bbcea4d..15ccdc229 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -41,6 +41,10 @@ files['/**/src/plugins/lua/greylist.lua'].globals = { 'math.ifloor', } +files['/**/lualib/lua_util.lua'].globals = { + 'unpack', +} + files['/**/src/rspamadm/*'].globals = { 'ansicolors', 'getopt', diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index 8479d579b..a9abd901a 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -144,4 +144,9 @@ exports.is_rspamc_or_controller = function(task) return is_rspamc end +local unpack_function = table.unpack or unpack +exports.unpack = function(t) + return unpack_function(t) +end + return exports diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua index b8d211ae7..e25ea42db 100644 --- a/src/plugins/lua/ratelimit.lua +++ b/src/plugins/lua/ratelimit.lua @@ -38,6 +38,7 @@ local rl_prefix = 'RL' local ip_score_lower_bound = 10 local ip_score_ham_multiplier = 1.1 local ip_score_spam_divisor = 1.1 +local limits_hash local message_func = function(_, limit_type) return string.format('Ratelimit "%s" exceeded', limit_type) @@ -511,13 +512,21 @@ local function ratelimit_cb(task) return process_buckets(task, args) end end + local params, method + if limits_hash then + params = {limits_hash, rspamd_lua_utils.unpack(redis_keys)} + method = 'HMGET' + else + method = 'MGET' + params = redis_keys + end local requested_keys = rspamd_redis_make_request(task, redis_params, -- connect params nil, -- hash key true, -- is write collect_cb, --callback - 'MGET', -- command - redis_keys -- arguments + method, -- command + params -- arguments ) if not requested_keys then rspamd_logger.errx(task, 'got error connecting to redis') @@ -678,6 +687,10 @@ if opts then message_func = assert(load(opts['message_func']))() end + if opts['limits_hash'] then + limits_hash = opts['limits_hash'] + end + redis_params = rspamd_parse_redis_server('ratelimit') if not redis_params then rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module') |