diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-06-22 14:10:22 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-06-22 14:10:22 +0100 |
commit | c2392de111b13a03a9c7c33bf56fb0949c0d31e3 (patch) | |
tree | eaa3fe8f7c9b97b2baec4a46c553bce09bc7a98a | |
parent | 4a09c608e4ccc7c9c83f54cd938ee0f31e76f0e5 (diff) | |
download | rspamd-c2392de111b13a03a9c7c33bf56fb0949c0d31e3.tar.gz rspamd-c2392de111b13a03a9c7c33bf56fb0949c0d31e3.zip |
[Feature] Add more options for redis config parsing function
-rw-r--r-- | src/lua/global_functions.lua | 47 |
1 files 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 |