redis#
Summary#
|
|
|
An async interface for caching objects in Redis. |
Module Contents#
- class RedisBackend(cache_name='aiohttp-cache', address='redis://localhost', **kwargs)#
Bases:
aiohttp_client_cache.backends.base.CacheBackend
Async cache backend for Redis (requires predis-py)
- __init__(cache_name='aiohttp-cache', address='redis://localhost', **kwargs)#
- Parameters
cache_name (
str
) – Used as a namespace (prefix for hash key)address (
str
) – Redis server URIexpire_after (Union[None, int, float, str, datetime.datetime, datetime.timedelta]) – Time after which a cache entry will be expired; see Cache Expiration for possible formats
urls_expire_after (Dict[str, Union[None, int, float, str, datetime.datetime, datetime.timedelta]]) – Expiration times to apply for different URL patterns
allowed_codes (tuple) – Only cache responses with these status codes
allowed_methods (tuple) – Only cache requests with these HTTP methods
include_headers (bool) – Cache requests with different headers separately
ignored_params (Iterable) – Request parameters to be excluded from the cache key
cache_control (bool) – Use Cache-Control response headers
filter_fn (Callable) – function that takes a
aiohttp.ClientResponse
object and returns a boolean indicating whether or not that response should be cached. Will be applied to both new and previously cached responsessecret_key (Union[Iterable, str, bytes]) – Optional secret key used to sign cache items for added security
salt (Union[str, bytes]) – Optional salt used to sign cache items
serializer – Custom serializer that provides
loads
anddumps
methodsdb (Union[str, int]) – Redis database index to switch to when connected
username (Optional[str]) – Username to use if Redis server instance requires authorization
password (Optional[str]) – Password to use if Redis server instance requires authorization
decode_responses (bool) – Enable response decoding
encoding (str) – Codec to use for response decoding
socket_timeout (Optional[float]) – Timeout for a dropped connection, in seconds
socket_connect_timeout (Optional[float]) – Timeout for a initial connection, in seconds
retry_on_timeout (bool) – Retry when the connection times out
socket_keepalive (bool) –
socket_keepalive_options (Optional[Mapping[int, Union[int, bytes]]]) –
socket_type (int) –
encoding_errors (str) –
socket_read_size (int) –
health_check_interval (float) –
- Parameters
cache_name (
str
) –address (
str
) –expire_after (Union[None, int, float, str, datetime.datetime, datetime.timedelta]) –
urls_expire_after (Dict[str, Union[None, int, float, str, datetime.datetime, datetime.timedelta]]) –
allowed_codes (tuple) –
allowed_methods (tuple) –
include_headers (bool) –
ignored_params (Iterable) –
cache_control (bool) –
filter_fn (Callable) –
socket_keepalive (bool) –
socket_keepalive_options (Optional[Mapping[int, Union[int, bytes]]]) –
socket_type (int) –
retry_on_timeout (bool) –
encoding (str) –
encoding_errors (str) –
decode_responses (bool) –
socket_read_size (int) –
health_check_interval (float) –
- async close()#
Close any active connections
- class RedisCache(namespace, collection_name, address='redis://localhost', connection=None, **kwargs)#
Bases:
aiohttp_client_cache.backends.base.BaseCache
An async interface for caching objects in Redis.
- Parameters
Note: The hash key name on the redis server will be
namespace:collection_name
.- _abc_impl = <_abc_data object>#
- async clear()#
Delete all items from the cache
- async close()#
- async delete(key)#
Delete an item from the cache. Does not raise an error if the item is missing.
- Parameters
key (
str
) –
- async get_connection()#
Lazy-initialize redis connection
- async keys()#
Get all keys stored in the cache
- Return type
- async read(key)#
Read an item from the cache. Returns
None
if the item is missing.
- async values()#
Get all values stored in the cache
- Return type