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.
Note
an empty string is returned if the key is not found.
- Parameters:
key – the preference key.
- Returns:
preference value on success, nil otherwise.
-
function getPrefs()
Retrieve many ntopng preferences.
- Returns:
table (pref_name -> pref_value).
-
function flushCache()
Completely flushes any preference and cached value.
- Returns:
true on success, false otherwise.
-
function listIndexCache(string key, int index)
Retrieve a specific item in a Redis list.
Note
this is equivalent to the lindex operation (https://redis.io/commands/lindex)
- Parameters:
key – the list item identifier.
index – the list index.
- Returns:
the item on success, nil otherwise.
-
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.
- Parameters:
queue_name – the queue_name name.
- Returns:
the poped value on success, nil otherwise.
-
function rpopCache(string queue_name)
Right pop a value from a persistent queue.
- Parameters:
queue_name – the queue_name name.
- Returns:
the poped value on success, nil otherwise.
-
function lremCache(string queue_name, string item)
Removes the first of the item in the queue.
- Parameters:
queue_name – the queue_name name.
item – the item to remove.
- Returns:
true on success, false otherwise.
-
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.
- Parameters:
queue_name – the queue_name name.
start_idx – the lower index for item range.
end_idx – the upper index for item range.
- Returns:
table with retrieved item on success, nil otherwise.
-
function llenCache(string queue_name)
Get the length of a queue.
- Parameters:
queue_name – the queue_name name.
- Returns:
the queue length.
-
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.
- Parameters:
set_name – the name of the set.
- Returns:
set members on success, nil otherwiser.
-
function getHashCache(string map_name, string item_key)
Retrieve a value from a persistent key-value map.
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.
- Returns:
item value on success, nil otherwise.
-
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.
- Parameters:
map_name – the name of the map.
- Returns:
table (key -> “”) on success, nil otherwise.
-
function getHashAllCache(string map_name)
Retrieve all the key-value pairs of the specified persistent key-value map.
- Parameters:
map_name – the name of the map.
- Returns:
table (key -> value) on success, nil otherwise.
-
function getKeysCache(string pattern)
Retrieve all the preferences and cached keys matching the specified pattern.
- Parameters:
pattern – the string to search into the keys.
- Returns:
table (key -> “”) of matched keys on success, nil otherwise.