Module lua_redis
Module lua_redis
This module contains helper functions for working with Redis
Brief content:
Functions:
| Function | Description |
|---|---|
try_load_redis_servers(options, rspamd_config, no_fallback) | Tries to load redis servers from the specified options object. |
lua_redis.parse_redis_server(module_name, module_opts, no_fallback) | Extracts Redis server settings from configuration. |
lua_redis.redis_make_request(task, redis_params, key, is_write, callback, command, args) | Sends a request to Redis. |
lua_redis.redis_make_request_taskless(ev_base, cfg, redis_params, key, is_write, callback, command, args) | Sends a request to Redis in context where task is not available for some specific use-cases. |
lua_redis.request(redis_params, attrs, req) | Sends a request to Redis synchronously with coroutines or asynchronously using. |
lua_redis.connect(redis_params, attrs) | Connects to Redis synchronously with coroutines or asynchronously using a callback (modern API). |
lua_redis.register_prefix(prefix, module, description[, optional]) | Register new redis prefix for documentation purposes. |
lua_redis.prefixes([mname]) | Returns prefixes for specific module (or all prefixes). |
lua_redis.prepare_redis_setup(redis_params[, opts], callback) | One-shot synchronous initialization of a Redis connection for contexts. |
Functions
The module lua_redis defines the following functions.
Function try_load_redis_servers(options, rspamd_config, no_fallback)
Tries to load redis servers from the specified options object.
Returns redis_params table or nil in case of failure
Parameters:
No parameters
Returns:
No return
Back to module description.
Function lua_redis.parse_redis_server(module_name, module_opts, no_fallback)
Extracts Redis server settings from configuration
Parameters:
module_name {string}: name of module to get settings formodule_opts {table}: settings for module ornilto fetch them from configurationno_fallback {boolean}: should betrueif global settings must not be used
Returns:
{table}: redis server settings
Example:
local rconfig = lua_redis.parse_redis_server('my_module')
-- rconfig contains upstream_list objects in ['write_servers'] and ['read_servers']
-- ['timeout'] contains timeout in seconds
-- ['expand_keys'] if true tells that redis key expansion is enabled
Back to module description.
Function lua_redis.redis_make_request(task, redis_params, key, is_write, callback, command, args)
Sends a request to Redis
Parameters:
task {rspamd_task}: task objectredis_params {table}: redis configuration in format returned by lua_redis.parse_redis_server()key {string}: key to use for shardingis_write {boolean}: should betrueif we are performing a write operatingcallback {function}: callback function (first parameter is error if applicable, second is a 2D array (table))command {string}: Redis command to runargs {table}: Numerically indexed table containing arguments for command
Returns:
No return
Back to module description.
Function lua_redis.redis_make_request_taskless(ev_base, cfg, redis_params, key, is_write, callback, command, args)
Sends a request to Redis in context where task is not available for some specific use-cases
Identical to redis_make_request() except in that first parameter is an event base object and the second one is the 'config' object
Parameters:
No parameters
Returns:
No return
Back to module description.
Function lua_redis.request(redis_params, attrs, req)
Sends a request to Redis synchronously with coroutines or asynchronously using a callback (modern API)
Parameters:
redis_params {no type}: a table of redis server parametersattrs {no type}: a table of redis request attributes (e.g. task, or ev_base + cfg + session)req {no type}: a table of request: a command + command options
Returns:
{result,data/connection,address}: boolean result, connection object in case of async request and results if using coroutines, redis server address
Back to module description.
Function lua_redis.connect(redis_params, attrs)
Connects to Redis synchronously with coroutines or asynchronously using a callback (modern API)
Parameters:
redis_params {no type}: a table of redis server parametersattrs {no type}: a table of redis request attributes (e.g. task, or ev_base + cfg + session)
Returns:
{result,connection,address}: boolean result, connection object, redis server address
Back to module description.
Function lua_redis.register_prefix(prefix, module, description[, optional])
Register new redis prefix for documentation purposes
Parameters:
prefix {string}: string prefixmodule {string}: module namedescription {string}: prefix descriptionoptional {table}: optional kv pairs (e.g. pattern)
Returns:
No return
Back to module description.
Function lua_redis.prefixes([mname])
Returns prefixes for specific module (or all prefixes). Returns a table prefix -> table
Parameters:
No parameters
Returns:
No return
Back to module description.
Function lua_redis.prepare_redis_setup(redis_params[, opts], callback)
One-shot synchronous initialization of a Redis connection for contexts
where rspamd_config:add_on_load callbacks never fire (typically rspamadm
tools). Performs, per opts, sentinel resolution and script loading,
then invokes callback(err) once Redis is ready.
{
sentinels = true, -- resolve Sentinels if redis_params.sentinels is set
scripts = true, -- true = all scripts bound to redis_params,
-- false = skip script loading,
-- { id1, id2, ... } = only those add_redis_script ids
timeout = nil, -- override timeout (seconds) for setup IO
ev_base = nil, -- defaults to rspamadm_ev_base
session = nil, -- defaults to rspamadm_session
config = nil, -- defaults to rspamd_config
}
a string describing the failure.
Parameters:
redis_params {table}: parsed redis params (fromparse_redis_server).opts {table}: (optional) merged vialua_util.override_defaultsover:callback {function}:callback(err)—errisnilon success or
Returns:
No return
Back to module description.
Back to top.