]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Add support of read only redis params
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 19 Apr 2018 12:42:23 +0000 (13:42 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 19 Apr 2018 12:42:23 +0000 (13:42 +0100)
lualib/lua_redis.lua
src/plugins/lua/bayes_expiry.lua

index 1be476fbe06f1e018822b8af06a5cc1cf23be645..bb229479cfb46777730cb84ba5d0cbbed991199e 100644 (file)
@@ -32,6 +32,7 @@ local function try_load_redis_servers(options, rspamd_config, result)
   local default_timeout = 1.0
   local default_expand_keys = false
   local upstream_list = require "rspamd_upstream_list"
+  local read_only = true
 
   -- Try to get read servers:
   local upstreams_read, upstreams_write
@@ -51,6 +52,7 @@ local function try_load_redis_servers(options, rspamd_config, result)
     else
       upstreams_read = upstream_list.create(options['servers'], default_port)
     end
+    read_only = false
   elseif options['server'] then
     if rspamd_config then
       upstreams_read = upstream_list.create(rspamd_config,
@@ -58,18 +60,20 @@ local function try_load_redis_servers(options, rspamd_config, result)
     else
       upstreams_read = upstream_list.create(options['server'], default_port)
     end
+    read_only = false
   end
 
   if upstreams_read then
     if options['write_servers'] then
       if rspamd_config then
         upstreams_write = upstream_list.create(rspamd_config,
-          options['write_servers'], default_port)
+                options['write_servers'], default_port)
       else
         upstreams_write = upstream_list.create(options['write_servers'],
-          default_port)
+                default_port)
       end
-    elseif not options['read_servers'] then
+      read_only = false
+    elseif not read_only then
       upstreams_write = upstreams_read
     end
   end
@@ -106,6 +110,12 @@ local function try_load_redis_servers(options, rspamd_config, result)
     result['password'] = options['password']
   end
 
+  if read_only and not result.write_servers then
+    result.read_only = true
+  elseif result.write_servers then
+    result.read_only = false
+  end
+
   if upstreams_read then
     result.read_servers = upstreams_read
     if upstreams_write then
index 0c3d277a859b8198e7e663a405366b8e54f6c8a9..f50484d537717dd1c48223918b167f03de6d1120 100644 (file)
@@ -81,7 +81,12 @@ local function check_redis_classifier(cls, cfg)
         end
       end
     end
-    if redis_params['read_servers'] ~= redis_params['write_servers'] then return end
+
+    if redis_params['read_only'] then
+      logger.infox(rspamd_config, 'disable expiry for classifier %s: read only redis configuration',
+          symbol_spam)
+      return
+    end
 
     table.insert(settings.classifiers, {
       symbol_spam = symbol_spam,