From: Andrew Lewis Date: Wed, 19 Jul 2017 13:18:42 +0000 (+0200) Subject: [Feature] Redis settings: support checking multiple keys X-Git-Tag: 1.6.3~1^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b6308ad23f0c04d6d6b61c3d9f3d2369556271a3;p=thirdparty%2Frspamd.git [Feature] Redis settings: support checking multiple keys --- diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua index bd0f4980e5..54b6d65cd7 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