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.key: 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
lpushCache(string queue_name, string value, 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, 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
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
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.