Module areixio.utils.simple_mq
Functions
def is_json(data: str)
Classes
class SignalMQ (conn: Redis = None, name: str = None)
-
Defines a simple FIFO message queue using Redis
Connects to a queue on Redis with the given name. Will create the queue if it does not exist.
Args: - conn: Redis connection object, e.g. conn = Redis() - name: optional name of this queue. If not defined a random ID will be generated.
Class variables
var RANDOM_NAME_LENGTH
var REDIS_KEY_PREFIX
Instance variables
var conn : Redis
var is_connected : str
var name : str
Methods
def clear(self) ‑> int
-
deletes all messages from the given queue. Returns number of cleared messages.
def dequeue(self) ‑> Optional[str]
-
dequeue one message from the queue. returns None if empty
def dequeue_bulk(self, max: int = None) ‑> List[str]
-
dequeue a list of message from the queue.
return no more than max message from queue returns all messages int the queue if max is not specified returns an empty list if queue is empty
def enqueue(self, message: str) ‑> int
-
enqueue one message int the queue
returns size of the queue after enqueuing
def enqueue_bulk(self, messages: List[str]) ‑> int
-
enqueue a list of messages into the queue at once
returns size of the queue after enqueuing
def publish(self, message: str)
def size(self) ‑> int
-
return current number of messages in the queue
def subscribe(self, callback: Callable)