redis

Summary

RedisBackend([cache_name, address])

RedisCache(namespace, collection_name[, ...])

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

Notes

Parameters:
  • cache_name (str) – Used as a namespace (prefix for hash key)

  • address (str) – Redis server URI

  • kwargs (Any) – Additional keyword arguments for CacheBackend or backend connection

class RedisCache(namespace, collection_name, address='redis://localhost', connection=None, **kwargs)

Bases: BaseCache

An async interface for caching objects in Redis.

Parameters:
  • namespace (str) – namespace to use

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

  • connection (Redis | None) – An existing connection object to reuse instead of creating a new one

  • address (str) – Address of Redis server

  • kwargs (Any) – Additional keyword arguments for aioredis.Redis

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

async bulk_delete(keys)

Requires redis version >=2.4

Parameters:

keys (set)

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

Parameters:

key (str)

Return type:

bool

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:

AsyncIterable[str]

async read(key)

Read an item from the cache. Returns None if the item is missing.

Parameters:

key (str)

Return type:

Union[CachedResponse, bytes, str, None]

async size()

Get the number of items in the cache

Return type:

int

async values()

Get all values stored in the cache

Return type:

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

async write(key, item)

Write an item to the cache

Parameters: