redis_cache_backend#

class starlite.cache.redis_cache_backend.RedisCacheBackendConfig#

Bases: BaseModel

Redis cache backend configuration.

url: str#

Redis connection URL.

db: Optional[int]#

Redis DB ID (optional)

port: Optional[int]#

Redis port (optional)

username: Optional[str]#

A username to use when connecting to Redis (optional)

password: Optional[str]#

A password to use when connecting to Redis (optional)

class starlite.cache.redis_cache_backend.RedisCacheBackend#

Bases: CacheBackendProtocol

Redis-based cache backend.

__init__(config: RedisCacheBackendConfig)#

Initialize RedisCacheBackend

Parameters:

config – required configuration to connect to Redis.

async get(key: str) Any#

Retrieve a value from cache corresponding to the given key.

Parameters:

key – name of cached value.

Returns:

Cached value if existing else None.

async set(key: str, value: Any, expiration: int) None#

Set a value in cache for a given key for a duration determined by expiration.

Parameters:
  • key – key to cache value under.

  • value – the value to be cached.

  • expiration – expiration of cached value in seconds.

Notes

  • expiration is in seconds.

  • return value is not used by Starlite internally.

Returns:

None

async delete(key: str) None#

Delete a value from the cache and removes the given key.

Parameters:

key – key to be deleted from the cache.

Notes

  • return value is not used by Starlite internally.

Returns:

None