REDIS CLient Reference¶
redis_client
¶
Async Redis client helpers for storing problems efficiently.
save_to_redis
async
¶
save_problem_redis
async
¶
Persist a Problem instance in Redis using msgpack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
The Problem instance to store. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The Redis key used (problem_id). |
Source code in src/clients/redis_client.py
load_problem_redis
async
¶
Retrieve a Problem payload from Redis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem_id
|
str
|
The UUID key used when saving the problem. |
required |
Returns:
| Type | Description |
|---|---|
Problem | None
|
dict | None: Decoded problem payload or None if missing. |
Source code in src/clients/redis_client.py
check_id_exists
async
¶
Check if a problem ID exists in Redis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem_id
|
str
|
The UUID key to check. |
required |
Returns: bool: True if the ID exists, False otherwise.
Source code in src/clients/redis_client.py
subscribe_to_problem_channel
async
¶
Subscribe to a Redis channel for pub/sub.
Returns:
| Name | Type | Description |
|---|---|---|
PubSub |
PubSub
|
The Redis PubSub object. |
Source code in src/clients/redis_client.py
receive_message
async
¶
Receive a message from the Redis PubSub channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pubsub
|
PubSub
|
The Redis PubSub object. |
required |
timeout
|
float
|
Time in seconds to wait for a message. |
required |
Returns:
| Type | Description |
|---|---|
dict | None
|
dict | None: The message data or None if no message. |
Source code in src/clients/redis_client.py
unsunscribe_and_close_pubsub
async
¶
Unsubscribe from all channels and close the PubSub connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pubsub
|
PubSub
|
The Redis PubSub object. |
required |
Source code in src/clients/redis_client.py
redis_sync_client
¶
Synchronous Redis client for solver workers.
create_redis_client
¶
Create a new synchronous Redis client.
Returns:
| Type | Description |
|---|---|
Redis
|
redis.Redis: A new Redis client instance. |
Raises:
| Type | Description |
|---|---|
Exception
|
If connection or ping fails. |
Source code in src/clients/redis_sync_client.py
save_solution_to_redis
¶
Save a solution to Redis and update the problem with solution data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Redis
|
Redis client instance. |
required |
solution
|
Solution
|
The Solution object containing problem_id, solution_data, and status. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If client is None. |
Exception
|
If save fails. |
Source code in src/clients/redis_sync_client.py
close_redis_client
¶
Safely close Redis client connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Optional[Redis]
|
The Redis client to close. |
required |