Mercurial > public > queues
changeset 12:59c8c47bcf12
Added QUEUE_REDIS_CONNECTION and QUEUE_REDIS_DB settings. QUEUE_REDIS_CONNECTION is required but QUEUE_REDIS_DB is optional.
author | mcroydon |
---|---|
date | Tue, 12 May 2009 14:20:28 +0000 |
parents | 586c2984188b |
children | e09cc844ff10 |
files | queues/backends/redisd.py |
diffstat | 1 files changed, 27 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/queues/backends/redisd.py Tue May 12 11:51:48 2009 +0000 +++ b/queues/backends/redisd.py Tue May 12 14:20:28 2009 +0000 @@ -6,20 +6,45 @@ from queues.backends.base import BaseQueue from queues import InvalidBackend, QueueException +import os try: import redis except ImportError: raise InvalidBackend("Unable to import redis.") -# TODO: Import host, port, db +CONN = DB = None + +try: + from django.conf import settings + CONN = getattr(settings, 'QUEUE_REDIS_CONNECTION', None) + DB = getattr(settings, 'QUEUE_REDIS_DB', None) +except: + CONN = os.environ.get('QUEUE_REDIS_CONNECTION', None) + DB = os.environ.get('QUEUE_REDIS_DB', None) + +if not CONN: + raise InvalidBackend("QUEUE_REDIS_CONNECTION not set.") + +try: + host, port = CONN.split(':') +except ValueError: + raise InvalidBackend("QUEUE_REDIS_CONNECTION should be in the format host:port (such as localhost:6379).") + +try: + port = int(port) +except ValueError: + raise InvalidBackend("Port portion of QUEUE_REDIS_CONNECTION should be an integer.") class Queue(BaseQueue): def __init__(self, name): try: self.name = name self.backend = 'redis' - self._connection = redis.Redis() + kwargs = {'host' : host, 'port' : int(port)} + if DB: + kwargs['db'] = DB + self._connection = redis.Redis(**kwargs) except redis.RedisError, e: raise QueueException, "%s" % e