Skip to content

Commit 8d187f9

Browse files
committed
make 'socket_timeout' and 'socket_connect_timeout' equivalent for TCP and UDS connections
1 parent ac15d52 commit 8d187f9

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

redis/connection.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ def __init__(
592592
self,
593593
db=0,
594594
password=None,
595+
socket_timeout=None,
596+
socket_connect_timeout=None,
595597
retry_on_timeout=False,
596598
retry_on_error=SENTINEL,
597599
encoding="utf-8",
@@ -627,6 +629,10 @@ def __init__(
627629
self.credential_provider = credential_provider
628630
self.password = password
629631
self.username = username
632+
self.socket_timeout = socket_timeout
633+
if socket_connect_timeout is None:
634+
socket_connect_timeout = socket_timeout
635+
self.socket_connect_timeout = socket_connect_timeout
630636
self.retry_on_timeout = retry_on_timeout
631637
if retry_on_error is SENTINEL:
632638
retry_on_error = []
@@ -927,17 +933,13 @@ def __init__(
927933
self,
928934
host="localhost",
929935
port=6379,
930-
socket_timeout=None,
931-
socket_connect_timeout=None,
932936
socket_keepalive=False,
933937
socket_keepalive_options=None,
934938
socket_type=0,
935939
**kwargs,
936940
):
937941
self.host = host
938942
self.port = int(port)
939-
self.socket_timeout = socket_timeout
940-
self.socket_connect_timeout = socket_connect_timeout or socket_timeout
941943
self.socket_keepalive = socket_keepalive
942944
self.socket_keepalive_options = socket_keepalive_options or {}
943945
self.socket_type = socket_type
@@ -1158,9 +1160,8 @@ def _connect(self):
11581160
class UnixDomainSocketConnection(AbstractConnection):
11591161
"Manages UDS communication to and from a Redis server"
11601162

1161-
def __init__(self, path="", socket_timeout=None, **kwargs):
1163+
def __init__(self, path="", **kwargs):
11621164
self.path = path
1163-
self.socket_timeout = socket_timeout
11641165
super().__init__(**kwargs)
11651166

11661167
def repr_pieces(self):
@@ -1172,8 +1173,9 @@ def repr_pieces(self):
11721173
def _connect(self):
11731174
"Create a Unix domain socket connection"
11741175
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
1175-
sock.settimeout(self.socket_timeout)
1176+
sock.settimeout(self.socket_connect_timeout)
11761177
sock.connect(self.path)
1178+
sock.settimeout(self.socket_timeout)
11771179
return sock
11781180

11791181
def _host_error(self):

0 commit comments

Comments
 (0)