redis#
Summary#
|
|
|
An async interface for caching objects in Redis. |
Module Contents#
- class RedisBackend(cache_name='aiohttp-cache', address='redis://localhost', **kwargs)#
Bases:
CacheBackend
Async cache backend for Redis (requires redis-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 (None | int | float | str | datetime | timedelta) – Time after which a cache entry will be expired; see Cache Expiration for possible formats
urls_expire_after (Dict[str, None | int | float | str | datetime | timedelta] | None) – Expiration times to apply for different URL patterns
allowed_codes (Tuple[int, ...]) – Only cache responses with these status codes
allowed_methods (Tuple[str, ...]) – Only cache requests with these HTTP methods
include_headers (bool) – Cache requests with different headers separately
ignored_params (Iterable[str] | None) – Request parameters to be excluded from the cache key
cache_control (bool) – Use Cache-Control response headers
filter_fn (Callable[[
aiohttp.ClientResponse
| CachedResponse], bool] | Callable[[aiohttp.ClientResponse
| CachedResponse], Awaitable[bool]]) – function that takes aaiohttp.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 (Iterable | str | bytes | None) – Optional secret key used to sign cache items for added security
serializer – Custom serializer that provides
loads
anddumps
methodsdb (str | int) – Redis database index to switch to when connected
username (str | None) – Username to use if Redis server instance requires authorization
password (str | None) – 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 (float | None) – Timeout for a dropped connection, in seconds
socket_connect_timeout (float | None) – Timeout for a initial connection, in seconds
retry_on_timeout (bool) – Retry when the connection times out
kwargs (
Any
) –socket_keepalive (bool) –
socket_keepalive_options (Mapping[int, int | bytes] | None) –
socket_type (int) –
encoding_errors (str) –
socket_read_size (int) –
health_check_interval (float) –
client_name (str | None) –
- Parameters:
cache_name (
str
) –address (
str
) –kwargs (
Any
) –expire_after (None | int | float | str | datetime | timedelta) –
urls_expire_after (Dict[str, None | int | float | str | datetime | timedelta] | None) –
include_headers (bool) –
cache_control (bool) –
filter_fn (Callable[[
aiohttp.ClientResponse
| CachedResponse], bool] | Callable[[aiohttp.ClientResponse
| CachedResponse], Awaitable[bool]]) –password (str | None) –
socket_timeout (float | None) –
socket_connect_timeout (float | None) –
socket_keepalive (bool) –
socket_keepalive_options (Mapping[int, int | bytes] | None) –
socket_type (int) –
retry_on_timeout (bool) –
encoding (str) –
encoding_errors (str) –
decode_responses (bool) –
socket_read_size (int) –
health_check_interval (float) –
client_name (str | None) –
username (str | None) –
- async close()#
Close any active connections
- class RedisCache(namespace, collection_name, address='redis://localhost', connection=None, **kwargs)#
Bases:
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()#
Close any active connections, if applicable
- async contains(key)#
Check if a key is stored in the cache
- 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: