diff core/services.py @ 879:a423e8fd082d

Access redis via UNIX socket.
author Brian Neal <bgneal@gmail.com>
date Sat, 03 Jan 2015 18:22:48 -0600
parents ee87ea74d46b
children
line wrap: on
line diff
--- a/core/services.py	Sat Jan 03 14:24:52 2015 -0600
+++ b/core/services.py	Sat Jan 03 18:22:48 2015 -0600
@@ -11,11 +11,15 @@
 REDIS_HOST = getattr(settings, 'REDIS_HOST', 'localhost')
 REDIS_PORT = getattr(settings, 'REDIS_PORT', 6379)
 REDIS_DB = getattr(settings, 'REDIS_DB', 0)
+REDIS_SOCKET = getattr(settings, 'REDIS_UNIX_SOCKET', None)
 
 
-def get_redis_connection(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB):
+def get_redis_connection(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB,
+                         unix_socket_path=REDIS_SOCKET):
     """
     Create and return a Redis connection using the supplied parameters.
 
     """
+    if unix_socket_path:
+        return redis.StrictRedis(unix_socket_path=unix_socket_path, db=db)
     return redis.StrictRedis(host=host, port=port, db=db)