DictDatabase¶
-
class
pyrubrum.
DictDatabase
¶ Reduced implementation of a database using a dictionary, without the assignment of an expire to a key whenever one is added to the database.
Warning
It not recommended to use this in production, as it does not implement expires, while other implementations, such as
RedisDatabase
, do. In addition, any stored data will be erased as soon as the program stops executing. This implementation might be useful only in development and testing mode.-
get
(key: str) → str¶ Get the value which is associated to a certain key inside the database.
This method will query the key using
dict.get
. If the key is not defined within the dictionary,NotFoundError
is raised.- Parameters
key (str) – The key you are retrieving the value of from the dictionary.
- Returns
The value which is associated to the key in the dictionary.
- Return type
Optional[str]
- Raises
NotFoundError – If the provided key is not found.
-
set
(key: str, value: str, expire: Optional[Union[bool, int, datetime.timedelta]] = None)¶ Assign a value to a certain key inside the database. Note that this implementation ignores the setting of any expire.
This method will assign the provided value to the key using
dict.update
.
-
delete
(key: str)¶ Delete a certain key from the database, together with its stored value.
This method will delete the provided key from the database using
dict.pop
.- Parameters
key (str) – The key which is being deleted from the database, together with its linked data.
- Raises
NotFoundError – If the provided key is not found.
-