Mercurial > public > queues
changeset 37:e1298d634da4
Some PEP8 changes.
Allow the redis client to be provided. This will allow multiple queue instances to share a connection pool.
author | btimby |
---|---|
date | Sun, 23 Jun 2013 02:53:30 +0000 |
parents | 4ad156c4dbee |
children | 862e8846f7e5 |
files | queues/backends/redisd.py |
diffstat | 1 files changed, 8 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/queues/backends/redisd.py Sun May 20 01:49:11 2012 +0000 +++ b/queues/backends/redisd.py Sun Jun 23 02:53:30 2013 +0000 @@ -39,6 +39,7 @@ except ValueError: raise InvalidBackend("Port portion of QUEUE_REDIS_CONNECTION should be an integer.") + def _get_connection(host=host, port=port, db=DB, timeout=TIMEOUT): kwargs = {'host' : host, 'port' : port} if DB: @@ -56,12 +57,13 @@ kwargs['socket_timeout'] = kwargs.pop('timeout') return redis.Redis(**kwargs) + class Queue(BaseQueue): - def __init__(self, name): - try: + def __init__(self, name, connection=None): + try: self.name = name self.backend = 'redis' - self._connection = _get_connection() + self._connection = connection or _get_connection() except redis.RedisError, e: raise QueueException, "%s" % e @@ -101,10 +103,12 @@ def __repr__(self): return "<Queue %s>" % self.name + def create_queue(): """This isn't required, so we noop. Kept here for swapability.""" return True + def delete_queue(name): """Delete a queue""" try: @@ -116,5 +120,6 @@ except redis.RedisError, e: raise QueueException, "%s" % e + def get_list(): return _get_connection().keys('*')