From f705bfca0cb5ad510c0398a83cc0303908cef3e8 Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Wed, 19 Jul 2017 15:18:42 +0200 Subject: [PATCH] [Feature] Redis settings: support checking multiple keys --- src/plugins/lua/settings.lua | 43 ++++++++++++++++++++++++------------ 1 file 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 -- 2.39.5