diff options
Diffstat (limited to 'lualib/lua_redis.lua')
-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 |