From: Vsevolod Stakhov Date: Sat, 28 May 2016 12:21:02 +0000 (+0100) Subject: [Feature] Add universal function to parse redis servers for plugins X-Git-Tag: 1.3.0~425 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f7d54ff789833242766d565c79ea2e0d174dde45;p=rspamd.git [Feature] Add universal function to parse redis servers for plugins --- 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