|
1 | 1 | import datetime
|
2 | 2 | import time
|
3 | 3 | from itertools import chain, imap, izip, starmap
|
4 |
| -from redis.connection import ConnectionPool |
| 4 | +from redis.connection import ConnectionPool, UnixDomainSocketConnection |
5 | 5 | from redis.exceptions import (
|
6 | 6 | ConnectionError,
|
7 | 7 | DataError,
|
@@ -158,19 +158,28 @@ class Redis(object):
|
158 | 158 | def __init__(self, host='localhost', port=6379,
|
159 | 159 | db=0, password=None, socket_timeout=None,
|
160 | 160 | 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 |
174 | 183 |
|
175 | 184 | def pipeline(self, transaction=True, shard_hint=None):
|
176 | 185 | """
|
|
0 commit comments