aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Lewis <nerf@judo.za.org>2017-07-19 15:18:42 +0200
committerAndrew Lewis <nerf@judo.za.org>2017-07-19 15:18:42 +0200
commitf705bfca0cb5ad510c0398a83cc0303908cef3e8 (patch)
treedcfca33a3b6abde2621011a67b076062f205e146
parent32059ed6a7cbb9379ec0068b14f1e16f5097dbda (diff)
downloadrspamd-f705bfca0cb5ad510c0398a83cc0303908cef3e8.tar.gz
rspamd-f705bfca0cb5ad510c0398a83cc0303908cef3e8.zip
[Feature] Redis settings: support checking multiple keys
-rw-r--r--src/plugins/lua/settings.lua43
1 files changed, 29 insertions, 14 deletions
diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua
index bd0f4980e..54b6d65cd 100644
--- a/src/plugins/lua/settings.lua
+++ b/src/plugins/lua/settings.lua
@@ -558,18 +558,25 @@ local function gen_redis_callback(handler, id)
local key = handler(task)
local function redis_settings_cb(err, data)
- if not err and type(data) == 'string' then
- local parser = ucl.parser()
- local res,ucl_err = parser:parse_string(data)
- if not res then
- rspamd_logger.warnx(rspamd_config, 'cannot parse settings from redis: %s',
- ucl_err)
- else
- local obj = parser:get_object()
- rspamd_logger.infox(task, "<%1> apply settings according to redis rule %2",
- task:get_message_id(), id)
- task:set_settings(obj)
+ if not err and type(data) == 'table' then
+ for _, d in ipairs(data) do
+ if type(d) == 'string' then
+ local parser = ucl.parser()
+ local res,ucl_err = parser:parse_string(d)
+ if not res then
+ rspamd_logger.warnx(rspamd_config, 'cannot parse settings from redis: %s',
+ ucl_err)
+ else
+ local obj = parser:get_object()
+ rspamd_logger.infox(task, "<%1> apply settings according to redis rule %2",
+ task:get_message_id(), id)
+ task:set_settings(obj)
+ break
+ end
+ end
end
+ elseif err then
+ rspamd_logger.errx(task, 'Redis error: %1', err)
end
end
@@ -578,16 +585,24 @@ local function gen_redis_callback(handler, id)
return
end
+ local keys
+ if type(key) == 'table' then
+ keys = key
+ else
+ keys = {key}
+ end
+ key = keys[1]
+
local ret,_,_ = rspamd_redis_make_request(task,
redis_params, -- connect params
key, -- hash key
false, -- is write
redis_settings_cb, --callback
- 'GET', -- command
- {key} -- arguments
+ 'MGET', -- command
+ keys -- arguments
)
if not ret then
- rspamd_logger.errx(task, 'Redis GET failed: %s', ret)
+ rspamd_logger.errx(task, 'Redis MGET failed: %s', ret)
end
end
end