Redis Backend¶
- class cachelib.redis.RedisCache(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 Redis key-value store as a cache backend.
The first argument can be either a string denoting address of the Redis server or an object resembling an instance of a redis.Redis class.
Note: Python Redis API already takes care of encoding unicode strings on the fly.
- Parameters:
host (Any) – address of the Redis server or an object which API is compatible with the official Python Redis client (
redis-py).port (int) – port number on which Redis server listens for connections.
password (str | None) – password authentication for the Redis server.
db (int) – db (zero-based numeric index) on Redis 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 Redis 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
redis.Redis.- serializer = <cachelib.serializers.RedisSerializer object>¶