iotile.core.utilities.kvstore_mem

A simple in memory kv store for testing purposes.

Module Contents

class InMemoryKVStore(name, respect_venv=False)

A Key Value store based on an in memory dict

This is intended as a drop in replacement for SQLiteKVStore. Note that this KV store is not persistent across multiple process invocations so it is primarily useful for testing, not production use.

Args:
name (string): The name of the file to use as a persistent store for this KVStore. This
is ignored for this kv store type.
respect_venv (bool): Make folder relative to the current virtual environment if there
is one. This is ignored for this kv_store type
_shared_data
get(self, key)

Get a value by its key.

Args:
key (string): The key used to store this value
Returns:
value (string): The value associated to the key
Raises:
KeyError: if the key was not found
get_all(self)

Return a list of all (key, value) tuples in the kv store.

Returns:
list(string, string): A list of key, value pairs
remove(self, key)

Remove a key from the data store.

Args:
key (string): The key to remove
Raises:
KeyError: if the key was not found
try_get(self, key)

Try to get a value by its key, returning None if not found.

Args:
key (string): The key used to store this value
Returns:
value (string): The value associated to the key or None
set(self, key, value)

Set the value of a key.

Args:
key (string): The key used to store this value value (string): The value to store
clear(self)

Clear all values from this kv store.