# HG changeset patch # User Brian Neal # Date 1420330374 21600 # Node ID 862e8846f7e5f5a0df7f08bfe4b4e5283acb4614 # Parent e1298d634da47b99f442d6fc3cf0b8083ab9216b Fork; added UNIX socket support to redis backend. diff -r e1298d634da4 -r 862e8846f7e5 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sat Jan 03 18:12:54 2015 -0600 @@ -0,0 +1,2 @@ +syntax: glob +*.pyc diff -r e1298d634da4 -r 862e8846f7e5 README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Sat Jan 03 18:12:54 2015 -0600 @@ -0,0 +1,9 @@ +# queues # + +This is a friendly fork of the `queues` package found here: + +https://code.google.com/p/queues/ + +This fork adds the ability to use UNIX sockets in the `redis` backend. + +Mercurial fork repo location: https://bitbucket.org/bgneal/queues diff -r e1298d634da4 -r 862e8846f7e5 queues/backends/redisd.py --- a/queues/backends/redisd.py Sun Jun 23 02:53:30 2013 +0000 +++ b/queues/backends/redisd.py Sat Jan 03 18:12:54 2015 -0600 @@ -15,37 +15,50 @@ raise InvalidBackend("Unable to import redis.") CONN = DB = None +host = port = None try: from django.conf import settings CONN = getattr(settings, 'QUEUE_REDIS_CONNECTION', None) - DB = getattr(settings, 'QUEUE_REDIS_DB', None) + DB = getattr(settings, 'QUEUE_REDIS_DB', 0) TIMEOUT = getattr(settings, 'QUEUE_REDIS_TIMEOUT', None) + SOCKET = getattr(settings, 'QUEUE_REDIS_UNIX_SOCKET', None) except: CONN = os.environ.get('QUEUE_REDIS_CONNECTION', None) - DB = os.environ.get('QUEUE_REDIS_DB', None) + DB = os.environ.get('QUEUE_REDIS_DB', 0) TIMEOUT = os.environ.get('QUEUE_REDIS_TIMEOUT', None) + SOCKET = os.environ.get('QUEUE_REDIS_UNIX_SOCKET', None) -if not CONN: - raise InvalidBackend("QUEUE_REDIS_CONNECTION not set.") +if not CONN and not SOCKET: + raise InvalidBackend("QUEUE_REDIS_CONNECTION or QUEUE_REDIS_UNIX_SOCKET not set.") + +if not SOCKET: + 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.") try: - host, port = CONN.split(':') + DB = int(DB) except ValueError: - raise InvalidBackend("QUEUE_REDIS_CONNECTION should be in the format host:port (such as localhost:6379).") + raise InvalidBackend("QUEUE_REDIS_DB should be an integer.") -try: - port = int(port) -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, socket=SOCKET): + if socket: + # Only Andy McCurdy's library supports this + return redis.Redis(unix_socket_path=socket, db=db) -def _get_connection(host=host, port=port, db=DB, timeout=TIMEOUT): kwargs = {'host' : host, 'port' : port} - if DB: - kwargs['db'] = DB - if timeout: + if timeout is not None: kwargs['timeout'] = float(timeout) + if db is not None: + kwargs['db'] = int(db) try: # Try using the "official" redis kwargs return redis.Redis(**kwargs)