Skip to content

Commit

Permalink
make 'socket_timeout' and 'socket_connect_timeout' equivalent for TCP…
Browse files Browse the repository at this point in the history
… and UDS connections
  • Loading branch information
woutdenolf committed May 1, 2023
1 parent ac15d52 commit 8d187f9
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,8 @@ def __init__(
self,
db=0,
password=None,
socket_timeout=None,
socket_connect_timeout=None,
retry_on_timeout=False,
retry_on_error=SENTINEL,
encoding="utf-8",
Expand Down Expand Up @@ -627,6 +629,10 @@ def __init__(
self.credential_provider = credential_provider
self.password = password
self.username = username
self.socket_timeout = socket_timeout
if socket_connect_timeout is None:
socket_connect_timeout = socket_timeout
self.socket_connect_timeout = socket_connect_timeout
self.retry_on_timeout = retry_on_timeout
if retry_on_error is SENTINEL:
retry_on_error = []
Expand Down Expand Up @@ -927,17 +933,13 @@ def __init__(
self,
host="localhost",
port=6379,
socket_timeout=None,
socket_connect_timeout=None,
socket_keepalive=False,
socket_keepalive_options=None,
socket_type=0,
**kwargs,
):
self.host = host
self.port = int(port)
self.socket_timeout = socket_timeout
self.socket_connect_timeout = socket_connect_timeout or socket_timeout
self.socket_keepalive = socket_keepalive
self.socket_keepalive_options = socket_keepalive_options or {}
self.socket_type = socket_type
Expand Down Expand Up @@ -1158,9 +1160,8 @@ def _connect(self):
class UnixDomainSocketConnection(AbstractConnection):
"Manages UDS communication to and from a Redis server"

def __init__(self, path="", socket_timeout=None, **kwargs):
def __init__(self, path="", **kwargs):
self.path = path
self.socket_timeout = socket_timeout
super().__init__(**kwargs)

def repr_pieces(self):
Expand All @@ -1172,8 +1173,9 @@ def repr_pieces(self):
def _connect(self):
"Create a Unix domain socket connection"
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.settimeout(self.socket_timeout)
sock.settimeout(self.socket_connect_timeout)
sock.connect(self.path)
sock.settimeout(self.socket_timeout)
return sock

def _host_error(self):
Expand Down

0 comments on commit 8d187f9

Please sign in to comment.