Skip to content

Redis

infra.adapters.redis

Summary

Redis-backed implementation of the report store port.


Persist and scan report payloads in Redis under the report:* key space.

Classes

RedisStoreAdaptor

1
2
3
4
RedisStoreAdaptor(
    url: str = "redis://localhost:6379/0",
    decode_responses: bool = True,
)

Bases: ReportStore

Adapt a Redis client to the report store port.

Attributes:

Name Type Description
_redis Redis

Asynchronous Redis client bound to the configured URL.

Initialize the adaptor with a Redis connection.

Parameters:

Name Type Description Default
url str

Redis connection URL.

'redis://localhost:6379/0'
decode_responses bool

Whether Redis returns decoded strings.

True
Functions
clear async
clear() -> None

Delete every report key from the store.

Notes

Scans REPORT_PREFIX and removes all matching keys in one call.

close async
close() -> None

Close the underlying Redis connection.

delete async
delete(key: str) -> None

Delete the value stored at key.

Parameters:

Name Type Description Default
key str

Redis key to remove.

required
get async
get(key: str) -> Optional[str]

Read the value stored at key.

Parameters:

Name Type Description Default
key str

Redis key to read.

required

Returns:

Type Description
Optional[str]

Optional[str]: Stored value, or None when the key is absent.

scan async
scan(pattern: str) -> List[str]

List keys matching pattern.

Parameters:

Name Type Description Default
pattern str

Glob-style key pattern.

required

Returns:

Type Description
List[str]

List[str]: Matching keys.

set async
set(key: str, value: str) -> None

Store value at key.

Parameters:

Name Type Description Default
key str

Redis key to write.

required
value str

Serialized value to persist.

required