aiohttp_client_cache.backends.redis module

class aiohttp_client_cache.backends.redis.RedisBackend(cache_name='aiohttp-cache', address='redis://localhost', **kwargs)[source]

Bases: aiohttp_client_cache.backends.base.CacheBackend

Redis cache backend

class aiohttp_client_cache.backends.redis.RedisCache(namespace, collection_name, address=None, connection=None, **kwargs)[source]

Bases: aiohttp_client_cache.backends.base.BaseCache

An async-compatible interface for caching objects in Redis.

Parameters
  • namespace (str) – namespace to use

  • collection_name (str) – name of the hash map stored in redis

  • connection (Optional[Redis]) – An existing connection object to reuse instead of creating a new one

  • address (Optional[str]) – Address of Redis server

  • kwargs – Additional keyword arguments for redis.Redis

Note: The hash key name on the redis server will be namespace:collection_name.

_abc_impl = <_abc_data object>
async clear()[source]

Delete all items from the cache

async contains(key)[source]

Check if a key is stored in the cache

Return type

bool

Parameters

key (str) –

async delete(key)[source]

Delete a single item from the cache. Does not raise an error if the item is missing.

Parameters

key (str) –

async get_connection()[source]

Lazy-initialize redis connection

async keys()[source]

Get all keys stored in the cache

Return type

Iterable[str]

async read(key)[source]

Read a single item from the cache. Returns None if the item is missing.

Return type

Union[CachedResponse, None, bytes, str]

Parameters

key (str) –

async size()[source]

Get the number of items in the cache

Return type

int

async values()[source]

Get all values stored in the cache

Return type

Iterable[Union[CachedResponse, None, bytes, str]]

async write(key, item)[source]

Write an item to the cache

Parameters