Valkey Backend¶
- class cachelib.valkey.ValkeyCache(host='localhost', port=6379, password=None, db=0, default_timeout=300, key_prefix=None, ignore_delete_many_errors=True, check_connection=False, **kwargs)¶
Bases:
BaseRedisCacheUses the Valkey key-value store as a cache backend.
The first argument can be either a string denoting address of the Valkey server or an object resembling an instance of a valkey.Valkey class.
Note: Python Valkey API already takes care of encoding unicode strings on the fly.
- Parameters:
host (Any) – address of the Valkey server or an object which API is compatible with the official Python Valkey client (
valkey-py).port (int) – port number on which Valkey server listens for connections.
password (str | None) – password authentication for the Valkey server.
db (int) – db (zero-based numeric index) on Valkey Server to connect.
default_timeout (int | timedelta) –
the default timeout that is used if no timeout is specified on
set(). Either a number of seconds or adatetime.timedelta. A timeout of 0 indicates that the cache never expires.Changed in version 0.17.0: Accepts a
datetime.timedelta.key_prefix (str | Callable[[], str] | None) – A prefix that should be added to all keys.
ignore_delete_many_errors (bool) –
If False, delete_many() will raise a RuntimeError if any key fails to delete. Keys that do not exist are considered successfully deleted and do not raise.
Changelog
Added in version 0.16.0.
check_connection (bool) –
If True, the constructor will verify the connection to the Valkey server and raise a RuntimeError if it fails. If False (default), connection errors are ignored at construction and surface on first use.
Changelog
Added in version 0.16.1.
kwargs (Any)
Any additional keyword arguments will be passed to
valkey.Valkey.- serializer = <cachelib.serializers.ValkeySerializer object>¶
- set_many(mapping, timeout=None)¶
Sets multiple keys and values from a mapping.
- Parameters:
- Returns:
A list containing all keys successfully set
- Return type: