comparison 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
comparison
equal deleted inserted replaced
878:fb0d2871afa4 879:a423e8fd082d
9 # Redis connection and database settings 9 # Redis connection and database settings
10 10
11 REDIS_HOST = getattr(settings, 'REDIS_HOST', 'localhost') 11 REDIS_HOST = getattr(settings, 'REDIS_HOST', 'localhost')
12 REDIS_PORT = getattr(settings, 'REDIS_PORT', 6379) 12 REDIS_PORT = getattr(settings, 'REDIS_PORT', 6379)
13 REDIS_DB = getattr(settings, 'REDIS_DB', 0) 13 REDIS_DB = getattr(settings, 'REDIS_DB', 0)
14 REDIS_SOCKET = getattr(settings, 'REDIS_UNIX_SOCKET', None)
14 15
15 16
16 def get_redis_connection(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB): 17 def get_redis_connection(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB,
18 unix_socket_path=REDIS_SOCKET):
17 """ 19 """
18 Create and return a Redis connection using the supplied parameters. 20 Create and return a Redis connection using the supplied parameters.
19 21
20 """ 22 """
23 if unix_socket_path:
24 return redis.StrictRedis(unix_socket_path=unix_socket_path, db=db)
21 return redis.StrictRedis(host=host, port=port, db=db) 25 return redis.StrictRedis(host=host, port=port, db=db)