Module rspamd_cdb

Rspamd CDB module is used to read and write key/value pairs to the CDB file

Example:

local rspamd_cdb = require "rspamd_cdb"
rspamd_cdb.build('/tmp/test.cdb'):add('test', 'value'):finalize()
local c = rspamd_cdb.open('/tmp/test.cdb')
c:find('test')
-- will return 'value'

Brief content:

Functions:

Function Description
rspamd_cdb.open(filename, [ev_base]) Opens an existing CDB for reading.
rspamd_cdb.build(filename, [mode]) Creates a new cdb in a file (existing one will be overwritten!).

Methods:

Method Description
rspamd_cdb:find(key) Finds a specific key in cdb and returns a string or nil if a key has not been found.
rspamd_cdb:get_name() Returns filename for the specific cdb.
rspamd_cdb_builder:add(key, value) Adds new value to cdb in the builder mode.
rspamd_cdb_builder:finalize() Finalizes the CDB and writes it to disk.

Functions

The module rspamd_cdb defines the following functions.

Function rspamd_cdb.open(filename, [ev_base])

Opens an existing CDB for reading. If ev_base is specified, then cdb file is added for monitoring, that will get updates on disk file changes.

Parameters:

  • filename {string}: path to file
  • event {ev_base}: loop object

Returns:

  • {rspamd_cdb}: cdb object

Back to module description.

Function rspamd_cdb.build(filename, [mode])

Creates a new cdb in a file (existing one will be overwritten!). The object returned can be used merely for adding data. Upon finalizing, the data is written to disk and cdb can no longer be changed.

Parameters:

  • filename {string}: path to file
  • mode {int}: numeric mode to create a file

Returns:

  • {rspamd_cdb_builder}: cdb builder object (or nil + error message)

Back to module description.

Methods

The module rspamd_cdb defines the following methods.

Method rspamd_cdb:find(key)

Finds a specific key in cdb and returns a string or nil if a key has not been found

Parameters:

  • key {string}: key to find

Returns:

  • {string/nil}: value for the specific key

Back to module description.

Method rspamd_cdb:get_name()

Returns filename for the specific cdb

Parameters:

No parameters

Returns:

  • {string}: filename for cdb

Back to module description.

Method rspamd_cdb_builder:add(key, value)

Adds new value to cdb in the builder mode

Parameters:

  • key {string}: key to add
  • value {string}: value to associate with the key

Returns:

  • {rspamd_cdb_builder}: the same object to allow chaining calls

Back to module description.

Method rspamd_cdb_builder:finalize()

Finalizes the CDB and writes it to disk. This method also closes FD associated with CDB builder. No further additions are allowed after this point

Parameters:

No parameters

Returns:

No return

Back to module description.

Back to top.