summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2011-05-23 20:30:35 -0700
committerAndy McCurdy <andy@andymccurdy.com>2011-05-23 20:30:35 -0700
commitc8a9ec60167afff8a340d9b732b0b1e003b289e2 (patch)
tree71b7f223a69acc005e097a960ec5324e339915b3
parent3dafc29ce8b3be295f5a6bdc354bfb57b7fb061a (diff)
downloadredis-py-c8a9ec60167afff8a340d9b732b0b1e003b289e2.tar.gz
ability to use the UnixDomainSocketConnection directly from the Redis client.
-rw-r--r--redis/client.py37
1 files changed, 23 insertions, 14 deletions
diff --git a/redis/client.py b/redis/client.py
index 58b02ca..371bd20 100644
--- a/redis/client.py
+++ b/redis/client.py
@@ -1,7 +1,7 @@
import datetime
import time
from itertools import chain, imap, izip, starmap
-from redis.connection import ConnectionPool
+from redis.connection import ConnectionPool, UnixDomainSocketConnection
from redis.exceptions import (
ConnectionError,
DataError,
@@ -158,19 +158,28 @@ class Redis(object):
def __init__(self, host='localhost', port=6379,
db=0, password=None, socket_timeout=None,
connection_pool=None,
- charset='utf-8', errors='strict'):
- if connection_pool:
- self.connection_pool = connection_pool
- else:
- self.connection_pool = ConnectionPool(
- host=host,
- port=port,
- db=db,
- password=password,
- socket_timeout=socket_timeout,
- encoding=charset,
- encoding_errors=errors
- )
+ charset='utf-8', errors='strict', path=None):
+ if not connection_pool:
+ kwargs = {
+ 'db': db,
+ 'password': password,
+ 'socket_timeout': socket_timeout,
+ 'encoding': charset,
+ 'encoding_errors': errors
+ }
+ # based on input, setup appropriate connection args
+ if path:
+ kwargs.update({
+ 'path': path,
+ 'connection_class': UnixDomainSocketConnection
+ })
+ else:
+ kwargs.update({
+ 'host': host,
+ 'port': port
+ })
+ connection_pool = ConnectionPool(**kwargs)
+ self.connection_pool = connection_pool
def pipeline(self, transaction=True, shard_hint=None):
"""