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 dumps and loads, pickle is the default, use None to store messages in plain text (suitable for strings, integers, etc)
  • kwargs – additional kwargs to pass to Redis, most commonly host, 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 (block will default to True if 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; False by default
  • timeout – when using block, if no msg is available for timeout in seconds, give up and return None
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 (block will default to True if not given)