From c2392de111b13a03a9c7c33bf56fb0949c0d31e3 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 22 Jun 2016 14:10:22 +0100 Subject: [PATCH] [Feature] Add more options for redis config parsing function --- src/lua/global_functions.lua | 47 ++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/src/lua/global_functions.lua b/src/lua/global_functions.lua index 9cf5f9a6f..0aacd3989 100644 --- a/src/lua/global_functions.lua +++ b/src/lua/global_functions.lua @@ -5,20 +5,53 @@ function rspamd_parse_redis_server(module_name) local default_port = 6379 + local default_timeout = 1.0 local logger = require "rspamd_logger" local upstream_list = require "rspamd_upstream_list" local function try_load_redis_servers(options) - local key = options['servers'] + -- Try to get read servers: + local upstreams_read, upstreams_write - if not key then key = options['server'] end + if options['read_servers'] then + upstreams_read = upstream_list.create(rspamd_config, + options['read_servers'], default_port) + elseif options['servers'] then + upstreams_read = upstream_list.create(rspamd_config, + options['servers'], default_port) + elseif options['server'] then + upstreams_read = upstream_list.create(rspamd_config, + options['server'], default_port) + end - if key then - local upstreams = upstream_list.create(rspamd_config, key, default_port) + if upstreams_read then + if options['write_servers'] then + upstreams_write = upstream_list.create(rspamd_config, + options['read_servers'], default_port) + else + upstreams_write = upstreams_read + end + end - if upstreams then - return upstreams + if upstreams_write and upstreams_read then + local ret = { + read_servers = upstreams_read, + write_servers = upstreams_write, + } + ret['timeout'] = default_timeout + if options['timeout'] then + ret['timeout'] = tonumber(options['timeout']) + end + if options['prefix'] then + ret['prefix'] = options['prefix'] end + if options['db'] then + ret['db'] = options['db'] + end + if options['password'] then + ret['password'] = options['password'] + end + return ret end return nil @@ -62,4 +95,4 @@ function rspamd_str_split(s, sep) local elem = lpeg.C((1 - sep)^0) local p = lpeg.Ct(elem * (sep * elem)^0) -- make a table capture return lpeg.match(p, s) -end \ No newline at end of file +end -- 2.39.5