Valkey Backend

class cachelib.valkey.ValkeyCache(host='localhost', port=6379, password=None, db=0, default_timeout=300, key_prefix=None, **kwargs)

Bases: BaseRedisCache

Uses 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) – the default timeout that is used if no timeout is specified on set(). A timeout of 0 indicates that the cache never expires.

  • key_prefix (str | Callable[[], str] | None) – A prefix that should be added to all keys.

  • 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:
  • mapping (Dict[str, Any]) – a mapping with the keys/values to set.

  • timeout (int | None) – the cache timeout for the key in seconds (if not specified, it uses the default timeout). A timeout of 0 indicates that the cache never expires.

Returns:

A list containing all keys successfully set

Return type:

boolean