Module lua_redis

This module contains helper functions for working with Redis

Brief content:

Functions:

lua_redis.parse_redis_server(module_name, module_opts, no_fallback)

lua_redis.redis_make_request(task, redis_params, key, is_write, callback, command, args)

lua_redis.redis_make_request_taskless(ev_base, redis_params, key, is_write, callback, command, args)

lua_redis.request(redis_params, attrs, req)

lua_redis.connect(redis_params, attrs)

Functions

The module lua_redis defines the following functions.

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: a table of redis server parameters
  • attrs: a table of redis request attributes (e.g. task, or ev_base + cfg + session)
  • req: 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: a table of redis server parameters
  • attrs: 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.

Back to top.