5.6.6.2. vlcp.service.utils.knowledge

Note

This document is generated from the source file.

View Source on GitHub

Created on 2015/11/9

author:hubo
class vlcp.service.utils.knowledge.Knowledge(server)

Simple KV-cache in memory. A base for other KV-DB. Data is automatically removed after timeout. Use knowledge instead of local storage in modules so data is not lost on module restarting.

__init__(server)

Constructor

delete(key)

Delete a key

get(key, timeout=None)

Get value from key

mget(keys)

Get multiple values from multiple keys

mgetwithcache(keys, cache=None)

Get multiple values, cached when possible

mset(kvpairs, timeout=None)

Set multiple values on multiple keys

mupdate(keys, updater, timeout=None)

Update multiple keys in-place one by one with a custom function, see update. Either all success, or all fail.

set(key, value, timeout=None)

Set value to key, with an optional timeout

update(key, updater, timeout=None)

Update in-place with a custom function

Parameters:
  • key – key to update
  • updaterfunc(k,v), should return a new value to update, or return None to delete
  • timeout – new timeout
Returns:

the updated value, or None if deleted

updateall(keys, updater, timeout=None)

Update multiple keys in-place, with a function updater(keys, values) which returns (updated_keys, updated_values). Either all success or all fail

updateallwithtime(keys, updater, timeout=None)

Update multiple keys in-place, with a function updater(keys, values, timestamp) which returns (updated_keys, updated_values). Either all success or all fail.

Timestamp is a integer standing for current time in microseconds.

class vlcp.service.utils.knowledge.MemoryStorage(server)
vlcp.service.utils.knowledge.escape_key(k)

Escape k, ensuring there is not a ‘.’ in the string.

vlcp.service.utils.knowledge.return_self_updater(func)

Run func, but still return v. Useful for using knowledge.update with operates like append, extend, etc. e.g. return_self(lambda k,v: v.append(‘newobj’))

vlcp.service.utils.knowledge.unescape_key(k)

Unescape key to get ‘.’ back