From 994f9676d2c016bb07ec53a0018aaa888ebe2d27 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 19 Apr 2018 13:42:23 +0100 Subject: [PATCH] [Minor] Add support of read only redis params --- lualib/lua_redis.lua | 16 +++++++++++++--- src/plugins/lua/bayes_expiry.lua | 7 ++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lualib/lua_redis.lua b/lualib/lua_redis.lua index 1be476fbe..bb229479c 100644 --- a/lualib/lua_redis.lua +++ b/lualib/lua_redis.lua @@ -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 diff --git a/src/plugins/lua/bayes_expiry.lua b/src/plugins/lua/bayes_expiry.lua index 0c3d277a8..f50484d53 100644 --- a/src/plugins/lua/bayes_expiry.lua +++ b/src/plugins/lua/bayes_expiry.lua @@ -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, -- 2.39.5