]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Redis settings: support checking multiple keys
authorAndrew Lewis <nerf@judo.za.org>
Wed, 19 Jul 2017 13:18:42 +0000 (15:18 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Wed, 26 Jul 2017 20:26:50 +0000 (22:26 +0200)
src/plugins/lua/settings.lua

index bd0f4980e5c8fe0e542b05d455f0928d5f5013e7..54b6d65cd7ffc744722c887378ba5ec54582d275 100644 (file)
@@ -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