Module rspamd_redis

This module implements redis asynchronous client for rspamd LUA API. Here is an example of using of this module:

Example:

local rspamd_redis = require "rspamd_redis"
local rspamd_logger = require "rspamd_logger"

local function symbol_callback(task)
	local redis_key = 'some_key'
	local function redis_cb(err, data)
		if not err then
			rspamd_logger.infox('redis returned %1=%2', redis_key, data)
		end
	end

	rspamd_redis.make_request(task, "127.0.0.1:6379", redis_cb,
		'GET', {redis_key})
	-- or in table form:
	-- rspamd_redis.make_request({task=task, host="127.0.0.1:6379,
	--	callback=redis_cb, timeout=2.0, cmd='GET', args={redis_key}})
end

Brief content:

Functions:

Function Description
rspamd_redis.make_request({params}) Make request to redis server, params is a table of key=value arguments in any order.
rspamd_redis.make_request_sync({params}) Make blocking request to redis server, params is a table of key=value arguments in any order.
rspamd_redis.connect({params}) Make request to redis server, params is a table of key=value arguments in any order.
rspamd_redis.connect_sync({params}) Make blocking request to redis server, params is a table of key=value arguments in any order.

Methods:

Method Description
rspamd_redis:add_cmd(cmd, {args}) Append new cmd to redis pipeline.
rspamd_redis:exec() Executes pending commands (suitable for blocking IO only for now).

Functions

The module rspamd_redis defines the following functions.

Function rspamd_redis.make_request({params})

Make request to redis server, params is a table of key=value arguments in any order

Parameters:

  • task {task}: worker task object
  • host {ip|string}: server address
  • callback {function}: callback to be called in form function (task, err, data)
  • cmd {string}: command to be sent to redis
  • args {table}: numeric array of strings used as redis arguments
  • timeout {number}: timeout in seconds for request (1.0 by default)

Returns:

  • {boolean}: true if a request has been scheduled

Back to module description.

Function rspamd_redis.make_request_sync({params})

Make blocking request to redis server, params is a table of key=value arguments in any order

Parameters:

  • host {ip|string}: server address
  • cmd {string}: command to be sent to redis
  • args {table}: numeric array of strings used as redis arguments
  • timeout {number}: timeout in seconds for request (1.0 by default)

Returns:

  • {boolean + result}: true and a result if a request has been successful

Back to module description.

Function rspamd_redis.connect({params})

Make request to redis server, params is a table of key=value arguments in any order

Parameters:

  • task {task}: worker task object
  • host {ip|string}: server address
  • timeout {number}: timeout in seconds for request (1.0 by default)

Returns:

  • {boolean,redis}: new connection object or nil if connection failed

Back to module description.

Function rspamd_redis.connect_sync({params})

Make blocking request to redis server, params is a table of key=value arguments in any order

Parameters:

  • host {ip|string}: server address
  • timeout {number}: timeout in seconds for request (1.0 by default)

Returns:

  • {redis}: redis object if a request has been successful

Back to module description.

Methods

The module rspamd_redis defines the following methods.

Method rspamd_redis:add_cmd(cmd, {args})

Append new cmd to redis pipeline

Parameters:

  • cmd {string}: command to be sent to redis
  • args {table}: array of strings used as redis arguments

Returns:

  • {boolean}: true if a request has been successful

Back to module description.

Method rspamd_redis:exec()

Executes pending commands (suitable for blocking IO only for now)

Parameters:

No parameters

Returns:

  • {boolean}: , {table}, …: pairs in format [bool, result] for each request pending

Back to module description.

Back to top.