1.2. Prefs API

The Prefs API provides key-value based persistent storage.

Functions

function setPref(string key, string value)

Set a persistent preference.

Note
by convention, preference keys should start with “ntopng.prefs.” .
Parameters
  • key: the preference key.
  • value: the preference value.

function getPref(string key)

Get a persistent preference.

Return
preference value on success, nil otherwise.
Note
an empty string is returned if the key is not found.
Parameters
  • key: the preference key.

function getPrefs()

Retrieve many ntopng preferences.

Return
table (pref_name -> pref_value).

function flushCache()

Completely flushes any preference and cached value.

Return
true on success, false otherwise.

function listIndexCache(string key, int index)

Retrieve a specific item in a Redis list.

Return
the item on success, nil otherwise.
Note
this is equivalent to the lindex operation (https://redis.io/commands/lindex)
Parameters
  • key: the list item identifier.
  • index: the list index.

function lpushCache(string queue_name, string value, int trim_size = nil)

Left push a persistent value on a queue.

Parameters
  • queue_name: the queue name.
  • value: the value to push.
  • trim_size: the maximum number of elements to keep in the queue.

function rpushCache(string queue_name, string value, int trim_size = nil)

Right push a persistent value on a queue.

Parameters
  • queue_name: the queue_name name.
  • value: the value to push.
  • trim_size: the maximum number of elements to keep in the queue.

function lpopCache(string queue_name)

Left pop a value from a persistent queue.

Return
the poped value on success, nil otherwise.
Parameters
  • queue_name: the queue_name name.

function rpopCache(string queue_name)

Right pop a value from a persistent queue.

Return
the poped value on success, nil otherwise.
Parameters
  • queue_name: the queue_name name.

function lremCache(string queue_name, string item)

Removes the first of the item in the queue.

Return
true on success, false otherwise.
Parameters
  • queue_name: the queue_name name.
  • item: the item to remove.

function ltrimCache(string queue_name, int start_idx, int end_idx)

Modify a persistent queue to only keep the items within the specified index range.

Parameters
  • queue_name: the queue_name name.
  • start_idx: the lower index for item range.
  • end_idx: the upper index for item range.

function lrangeCache(string queue_name, int start_idx = 0, int end_idx = -1)

Retrieves items from a persistent queue at the specified index range.

Return
table with retrieved item on success, nil otherwise.
Parameters
  • queue_name: the queue_name name.
  • start_idx: the lower index for item range.
  • end_idx: the upper index for item range.

function llenCache(string queue_name)

Get the length of a queue.

Return
the queue length.
Parameters
  • queue_name: the queue_name name.

function setMembersCache(string set_name, string value)

Insert the specified value into the set.

Parameters
  • set_name: the name of the set.
  • value: the item value to insert. This is unique within the set.

function delMembersCache(string set_name, string value)

Remove the specified value from the set.

Parameters
  • set_name: the name of the set.
  • value: the item value to remove.

function getMembersCache(string set_name)

Get all the members of the specified set.

Return
set members on success, nil otherwiser.
Parameters
  • set_name: the name of the set.

function getHashCache(string map_name, string item_key)

Retrieve a value from a persistent key-value map.

Return
item value on success, nil otherwise.
Note
an empty string is returned if the key is not found.
Parameters
  • map_name: the name of the map.
  • item_key: the name of the map.

function setHashCache(string map_name, string item_key, string item_value)

Store a value into a persistent key-value map.

Note
If an item for the specified key already exists, it will be replaced.
Parameters
  • map_name: the name of the map.
  • item_key: the item key within the map.
  • item_value: the item value to store.

function delHashCache(string map_name, string item_key)

Delete a value from a persistent key-value map.

Parameters
  • map_name: the name of the map.
  • item_key: the item key within the map.

function getHashKeysCache(string map_name)

Retrieve all the keys of the specified persistent key-value map.

Return
table (key -> “”) on success, nil otherwise.
Parameters
  • map_name: the name of the map.

function getHashAllCache(string map_name)

Retrieve all the key-value pairs of the specified persistent key-value map.

Return
table (key -> value) on success, nil otherwise.
Parameters
  • map_name: the name of the map.

function getKeysCache(string pattern)

Retrieve all the preferences and cached keys matching the specified pattern.

Return
table (key -> “”) of matched keys on success, nil otherwise.
Parameters
  • pattern: the string to search into the keys.