API Reference¶
-
hotqueue.key_for_name(name)¶ Return the key name used to store the given queue name in Redis.
-
class
hotqueue.HotQueue(name, serializer=pickle, **kwargs)¶ Simple FIFO message queue stored in a Redis list. Example:
>>> from hotqueue import HotQueue >>> queue = HotQueue("myqueue", host="localhost", port=6379, db=0)
Parameters: - name – name of the queue
- serializer – the class or module to serialize msgs with, must have
methods or functions named
dumpsandloads, pickle is the default, useNoneto store messages in plain text (suitable for strings, integers, etc) - kwargs – additional kwargs to pass to
Redis, most commonlyhost,port,db
-
key¶ Return the key name used to store this queue in Redis.
-
clear()¶ Clear the queue of all messages, deleting the Redis key.
-
consume(**kwargs)¶ Return a generator that yields whenever a message is waiting in the queue. Will block otherwise. Example:
>>> for msg in queue.consume(timeout=1): ... print msg my message another message
Parameters: kwargs – any arguments that get()can accept (blockwill default toTrueif not given)
-
get(block=False, timeout=None)¶ Return a message from the queue. Example:
>>> queue.get() 'my message' >>> queue.get() 'another message'
Parameters: - block – whether or not to wait until a msg is available in
the queue before returning;
Falseby default - timeout – when using
block, if no msg is available fortimeoutin seconds, give up and returnNone
- block – whether or not to wait until a msg is available in
the queue before returning;
-
put(*msgs)¶ Put one or more messages onto the queue. Example:
>>> queue.put("my message") >>> queue.put("another message")
To put messages onto the queue in bulk, which can be significantly faster if you have a large number of messages:
>>> queue.put("my message", "another message", "third message")
-
worker(*args, **kwargs)¶ Decorator for using a function as a queue worker. Example:
>>> @queue.worker(timeout=1) ... def printer(msg): ... print msg >>> printer() my message another message
You can also use it without passing any keyword arguments:
>>> @queue.worker ... def printer(msg): ... print msg >>> printer() my message another message
Parameters: kwargs – any arguments that get()can accept (blockwill default toTrueif not given)