Skip to content

Commit c8a9ec6

Browse files
committed
ability to use the UnixDomainSocketConnection directly from the Redis client.
1 parent 3dafc29 commit c8a9ec6

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

redis/client.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
22
import time
33
from itertools import chain, imap, izip, starmap
4-
from redis.connection import ConnectionPool
4+
from redis.connection import ConnectionPool, UnixDomainSocketConnection
55
from redis.exceptions import (
66
ConnectionError,
77
DataError,
@@ -158,19 +158,28 @@ class Redis(object):
158158
def __init__(self, host='localhost', port=6379,
159159
db=0, password=None, socket_timeout=None,
160160
connection_pool=None,
161-
charset='utf-8', errors='strict'):
162-
if connection_pool:
163-
self.connection_pool = connection_pool
164-
else:
165-
self.connection_pool = ConnectionPool(
166-
host=host,
167-
port=port,
168-
db=db,
169-
password=password,
170-
socket_timeout=socket_timeout,
171-
encoding=charset,
172-
encoding_errors=errors
173-
)
161+
charset='utf-8', errors='strict', path=None):
162+
if not connection_pool:
163+
kwargs = {
164+
'db': db,
165+
'password': password,
166+
'socket_timeout': socket_timeout,
167+
'encoding': charset,
168+
'encoding_errors': errors
169+
}
170+
# based on input, setup appropriate connection args
171+
if path:
172+
kwargs.update({
173+
'path': path,
174+
'connection_class': UnixDomainSocketConnection
175+
})
176+
else:
177+
kwargs.update({
178+
'host': host,
179+
'port': port
180+
})
181+
connection_pool = ConnectionPool(**kwargs)
182+
self.connection_pool = connection_pool
174183

175184
def pipeline(self, transaction=True, shard_hint=None):
176185
"""

0 commit comments

Comments
 (0)