Backend

At the moment, the library provides only one class for interacting with Redis.

Warning

Support for redis cluster is not yet available.

class redsession.backend.RedisBackend(redis)[source]

Bases: BaseAsyncBackend

This class is used to connect and interact with Redis.

Parameters:

redis (redis.asyncio.Redis) – Async Redis client.

Examples

You can find examples of work here:

FastAPI

Starlette

Base class

If you can implement your own logic. Just use the base class.

class redsession.backend.BaseAsyncBackend[source]

Bases: ABC

Base class with asynchronous methods for implementing your own logic of interaction with server sessions

abstract async delete(key)[source]

Removing user data from storage, must also include a key

Parameters:

key (str) – session key in storage.

Returns:

int if successful, None otherwise (Optional).

abstract async get(key)[source]

Getting session data by key (session ID).

Parameters:

key (str) – session key in storage.

Returns:

Dict if successful, None otherwise (Optional).

abstract async set(key, value, ex=None)[source]

Writing session information to storage.

Parameters:
  • key (str) – new session key to write.

  • value (Dict) – dictionary that stores user information.

  • ex (int | None) – key expiration time. if the value is None, the key must not expire.

Returns:

True if successful, None otherwise (Optional).

abstract async update(key, value)[source]

Updating a given session without changing the lifetime of the key.

Parameters:
  • key (str) – session key in storage.

  • value (Dict) – dictionary that stores user NEW information.

Returns:

True if successful, None otherwise (Optional).