diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-05 11:40:10 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-05 11:40:10 +0100 |
commit | 1a2844e855542edefb005b3896eddbe525358485 (patch) | |
tree | 41ebea58d0f49bf3d4953a07680c8b22f9cf2409 /lualib | |
parent | 5c9d86cd9630a3b689198cfc0cb128541355c3a7 (diff) | |
download | rspamd-1a2844e855542edefb005b3896eddbe525358485.tar.gz rspamd-1a2844e855542edefb005b3896eddbe525358485.zip |
[Feature] Implement Redis prefixes registration logic
Diffstat (limited to 'lualib')
-rw-r--r-- | lualib/lua_redis.lua | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lualib/lua_redis.lua b/lualib/lua_redis.lua index 0b3c54a7c..ae5fa2299 100644 --- a/lualib/lua_redis.lua +++ b/lualib/lua_redis.lua @@ -1584,5 +1584,46 @@ exports.connect = function(redis_params, attrs) end end +local redis_prefixes = {} + +--[[[ +-- @function lua_redis.register_prefix(prefix, module, description[, optional]) +-- Register new redis prefix for documentation purposes +-- @param {string} prefix string prefix +-- @param {string} module module name +-- @param {string} description prefix description +-- @param {table} optional optional kv pairs (e.g. pattern) +--]] +local function register_prefix(prefix, module, description, optional) + local pr = { + module = module, + description = description + } + + if optional and type(optional) == 'table' then + for k,v in pairs(optional) do + pr[k] = v + end + end + + redis_prefixes[prefix] = pr +end + +exports.register_prefix = register_prefix + +--[[[ +-- @function lua_redis.prefixes([mname]) +-- Returns prefixes for specific module (or all prefixes). Returns a table prefix -> table +--]] +exports.prefixes = function(mname) + if not mname then + return redis_prefixes + else + local fun = require "fun" + + return fun.totable(fun.filter(function(_, data) return data.module == mname end, + redis_prefixes)) + end +end return exports |