aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lua/global_functions.lua56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/lua/global_functions.lua b/src/lua/global_functions.lua
index e69de29bb..833832188 100644
--- a/src/lua/global_functions.lua
+++ b/src/lua/global_functions.lua
@@ -0,0 +1,56 @@
+
+-- This function parses redis server definition using either
+-- specific server string for this module or global
+-- redis section
+function rspamd_parse_redis_server(module_name)
+
+ local default_port = 6379
+ local logger = require "rspamd_logger"
+
+ local function try_load_redis_servers(options)
+ local key = options['servers']
+
+ if not key then key = options['server'] end
+
+ if key then
+ local upstreams = upstream_list.create(rspamd_config, key, default_port)
+
+ if upstreams then
+ return upstreams
+ end
+ end
+
+ return nil
+ end
+
+ local opts = rspamd_config:get_all_opt(module_name)
+ local ret
+
+ if opts then
+ ret = try_load_redis_servers(opts)
+ end
+
+ if ret then
+ return ret
+ end
+
+ opts = rspamd_config:get_all_opt('redis')
+
+ if opts then
+ if opts[module_name] then
+ ret = try_load_redis_servers(opts[module_name])
+ if ret then
+ return ret
+ end
+ else
+ ret = try_load_redis_servers(opts)
+
+ if ret then
+ logger.infox(rspamd_config, "using default redis server for module %s",
+ module_name)
+ end
+ end
+ end
+
+ return ret
+end