changeset 38:862e8846f7e5 tip

Fork; added UNIX socket support to redis backend.
author Brian Neal <bgneal@gmail.com>
date Sat, 03 Jan 2015 18:12:54 -0600
parents e1298d634da4
children
files .hgignore README.md queues/backends/redisd.py
diffstat 3 files changed, 38 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- /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
--- /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
--- 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)