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, 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).

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 for
  • module_opts {table}: settings for module or nil to fetch them from configuration
  • no_fallback {boolean}: should be true if 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 object
  • redis_params {table}: redis configuration in format returned by lua_redis.parse_redis_server()
  • key {string}: key to use for sharding
  • is_write {boolean}: should be true if we are performing a write operating
  • callback {function}: callback function (first parameter is error if applicable, second is a 2D array (table))
  • command {string}: Redis command to run
  • args {table}: Numerically indexed table containing arguments for command

Returns:

No return

Back to module description.

Function lua_redis.redis_make_request_taskless(ev_base, 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

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 parameters
  • attrs {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 parameters
  • attrs {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 prefix
  • module {string}: module name
  • description {string}: prefix description
  • optional {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.

Back to top.