peyk.fsm.storage.redis

Optional Redis-backed FSM storage.

Classes

AsyncRedisClient(*args, **kwargs)

Minimal async Redis surface required by RedisStorage.

RedisStorage([redis, state_ttl, data_ttl, ...])

Persist FSM state/data in Redis with independent optional TTLs.

class peyk.fsm.storage.redis.AsyncRedisClient(*args, **kwargs)[source]

Bases: Protocol

Minimal async Redis surface required by RedisStorage.

async get(key: str) str | bytes | None[source]

Performs the get operation for the FSM client.

Parameters:

key – Value used by this operation.

Returns:

Result produced by the FSM operation.

async set(key: str, value: str, *, ex: int | float | None = None) object[source]

Performs the set operation for the FSM client.

Parameters:
  • key – Value used by this operation.

  • value – Value used by this operation.

  • ex – Value used by this operation.

Returns:

Result produced by the FSM operation.

async delete(key: str) object[source]

Performs the delete operation for the FSM client.

Parameters:

key – Value used by this operation.

Returns:

Result produced by the FSM operation.

async aclose() None[source]

Performs the aclose operation for the FSM client.

class peyk.fsm.storage.redis.RedisStorage(redis: AsyncRedisClient | None = None, *, state_ttl: int | float | None = None, data_ttl: int | float | None = None, key_builder: KeyBuilder | None = None, url: str | None = None, prefix: str | None = None)[source]

Bases: BaseStorage

Persist FSM state/data in Redis with independent optional TTLs.

async get_state(key: StorageKey | str) str | None[source]

Return a stored state string, if present.

async set_state(key: StorageKey | str, state: str | None) None[source]

Set or clear state, applying state_ttl when configured.

async get_data(key: StorageKey | str) dict[str, object][source]

Decode JSON conversation data from Redis.

async set_data(key: StorageKey | str, data: Mapping[str, object]) None[source]

Replace JSON conversation data and apply data_ttl.

async update_data(key: StorageKey | str, data: Mapping[str, object] | None = None, **kwargs: object) dict[str, object][source]

Read, merge and persist conversation data.

async close() None[source]

Close the underlying Redis client when supported.