pynenc.broker.redis_broker¶
Module Contents¶
Classes¶
RedisQueue: A helper class for managing message queues in Redis. |
|
A Redis-backed implementation of the BaseBroker. |
API¶
- class pynenc.broker.redis_broker.RedisQueue(app: pynenc.app.Pynenc, client: redis.Redis, name: str, namespace: str = 'queue')[source]¶
RedisQueue: A helper class for managing message queues in Redis.
This class provides methods for sending, receiving, and purging messages in a Redis queue. It is designed to work specifically with the RedisBroker class to handle message queuing.
- Parameters:
app (Pynenc) – A reference to the Pynenc application.
client (redis.Redis) – A Redis client instance.
name (str) – The name of the queue.
namespace (str) – The namespace for the queue, defaults to ‘queue’.
Initialization
- send_message(message: str) None[source]¶
Send a message to the Redis queue.
This method appends a message to the right end of the Redis list, effectively queuing it for processing.
- Parameters:
message (str) – The message to be queued.
- receive_message() Optional[str][source]¶
Receive a message from the Redis queue.
This method pops a message from the left end of the Redis list. If a message is available, it is returned after decoding; otherwise, None is returned.
- Returns:
The message from the queue, or None if the queue is empty.
- class pynenc.broker.redis_broker.RedisBroker(app: pynenc.app.Pynenc)[source]¶
Bases:
pynenc.broker.base_broker.BaseBrokerA Redis-backed implementation of the BaseBroker.
This subclass of BaseBroker implements the abstract methods for routing, retrieving, and purging invocations using Redis as the message broker. It is suitable for production environments where robustness and scalability are required.
- Parameters:
app (Pynenc) – A reference to the Pynenc application.
Initialization
- route_invocation(invocation: pynenc.invocation.dist_invocation.DistributedInvocation) None[source]¶
Route an invocation by sending it to the Redis queue.
This method serializes the DistributedInvocation object to JSON and sends it to the Redis queue for processing using the
send_messagemethod.- Parameters:
invocation (DistributedInvocation) – The invocation to be queued.
- retrieve_invocation() Optional[pynenc.invocation.dist_invocation.DistributedInvocation][source]¶
Retrieve the next invocation from the Redis queue.
This method receives a message from the Redis queue using the
receive_messagemethod. If a message is received, it deserializes the JSON string back into a DistributedInvocation object.- Returns:
The next invocation from the queue, or None if the queue is empty.