redis_backend#

class starlite.middleware.session.redis_backend.RedisBackend#

Bases: ServerSideBackend[RedisBackendConfig]

Session backend to store data in redis.

__init__(config: RedisBackendConfig) None#

Initialize RedisBackend.

Notes

  • Requires redis. Install with pip install starlite[redis]

async get(session_id: str) Optional[Union[bytes, str]]#

Load data associated with session_id from redis.

Parameters:

session_id – The session-ID

Returns:

The session data, if existing, otherwise None.

async set(session_id: str, data: bytes) None#

Store data in redis under <prefix>:<session_id>

If there is already data associated with session_id, replace it with data and reset its expiry time

Parameters:
  • session_id – The session-ID

  • data – Serialized session data

Returns:

None

async delete(session_id: str) None#

Delete the data associated with session_id from redis. Fail silently if no such session-ID exists.

Parameters:

session_id – The session-ID

Returns:

None

async delete_all() None#

Delete all session data stored in redis.

Returns:

None

class starlite.middleware.session.redis_backend.RedisBackendConfig#

Bases: ServerSideSessionConfig

Configuration for RedisBackend

redis: Redis#

redis.asyncio.Redis instance.

key_prefix: str#

Prefix to store data under after the schema of <prefix>:<session-ID>