summaryrefslogtreecommitdiff
path: root/redis/connection.py
diff options
context:
space:
mode:
authorBar Shaul <88437685+barshaul@users.noreply.github.com>2022-01-25 09:01:48 +0200
committerGitHub <noreply@github.com>2022-01-25 09:01:48 +0200
commit039257613f523e6a30736f218ca2d37d2f12320f (patch)
tree0b8f7bade605d5978d36925ce69db6d6ae7cb4ea /redis/connection.py
parentfa5841e50c242a7584eedda59ea918570adbf729 (diff)
downloadredis-py-039257613f523e6a30736f218ca2d37d2f12320f.tar.gz
Added retry mechanism on socket timeouts when connecting to the server (#1895)
Diffstat (limited to 'redis/connection.py')
-rwxr-xr-xredis/connection.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/redis/connection.py b/redis/connection.py
index 5fdac54..508c196 100755
--- a/redis/connection.py
+++ b/redis/connection.py
@@ -604,7 +604,9 @@ class Connection:
if self._sock:
return
try:
- sock = self._connect()
+ sock = self.retry.call_with_retry(
+ lambda: self._connect(), lambda error: self.disconnect(error)
+ )
except socket.timeout:
raise TimeoutError("Timeout connecting to server")
except OSError as e:
@@ -721,7 +723,7 @@ class Connection:
if str_if_bytes(self.read_response()) != "OK":
raise ConnectionError("Invalid Database")
- def disconnect(self):
+ def disconnect(self, *args):
"Disconnects from the Redis server"
self._parser.on_disconnect()
if self._sock is None: