# HG changeset patch # User mcroydon # Date 1242138028 0 # Node ID 59c8c47bcf125f9f7c050c0bb7d31a9f338db698 # Parent 586c2984188ba87f9f428ddca74fd7c1fa34f8a2 Added QUEUE_REDIS_CONNECTION and QUEUE_REDIS_DB settings. QUEUE_REDIS_CONNECTION is required but QUEUE_REDIS_DB is optional. diff -r 586c2984188b -r 59c8c47bcf12 queues/backends/redisd.py --- 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