mirror of
https://github.com/rspamd/rspamd.git
synced 2024-08-12 02:10:19 +02:00
[Feature] Add universal function to parse redis servers for plugins
This commit is contained in:
parent
a109540436
commit
f7d54ff789
@ -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
|
Loading…
Reference in New Issue
Block a user