Skip to content

Commit 260b34e

Browse files
committed
Fixing the docs of some of the new methods in connection pools. Handle better retry_on_error handling on connection initialization.
1 parent a2744f3 commit 260b34e

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

redis/connection.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@
88
from abc import abstractmethod
99
from itertools import chain
1010
from queue import Empty, Full, LifoQueue
11-
from typing import Any, Callable, Dict, List, Literal, Optional, Type, TypeVar, Union
11+
from typing import (
12+
Any,
13+
Callable,
14+
Dict,
15+
Iterable,
16+
List,
17+
Literal,
18+
Optional,
19+
Type,
20+
TypeVar,
21+
Union,
22+
)
1223
from urllib.parse import parse_qs, unquote, urlparse
1324

1425
from redis.cache import (
@@ -311,7 +322,7 @@ def __init__(
311322
socket_timeout: Optional[float] = None,
312323
socket_connect_timeout: Optional[float] = None,
313324
retry_on_timeout: bool = False,
314-
retry_on_error=SENTINEL,
325+
retry_on_error: Union[Iterable[Type[Exception]], object] = SENTINEL,
315326
encoding: str = "utf-8",
316327
encoding_errors: str = "strict",
317328
decode_responses: bool = False,
@@ -367,19 +378,22 @@ def __init__(
367378
self.socket_connect_timeout = socket_connect_timeout
368379
self.retry_on_timeout = retry_on_timeout
369380
if retry_on_error is SENTINEL:
370-
retry_on_error = []
381+
retry_on_errors_list = []
382+
else:
383+
retry_on_errors_list = list(retry_on_error)
371384
if retry_on_timeout:
372385
# Add TimeoutError to the errors list to retry on
373-
retry_on_error.append(TimeoutError)
374-
self.retry_on_error = retry_on_error
375-
if retry or retry_on_error:
386+
retry_on_errors_list.append(TimeoutError)
387+
self.retry_on_error = retry_on_errors_list
388+
if retry or self.retry_on_error:
376389
if retry is None:
377390
self.retry = Retry(NoBackoff(), 1)
378391
else:
379392
# deep-copy the Retry object as it is mutable
380393
self.retry = copy.deepcopy(retry)
381-
# Update the retry's supported errors with the specified errors
382-
self.retry.update_supported_errors(retry_on_error)
394+
if self.retry_on_error:
395+
# Update the retry's supported errors with the specified errors
396+
self.retry.update_supported_errors(self.retry_on_error)
383397
else:
384398
self.retry = Retry(NoBackoff(), 0)
385399
self.health_check_interval = health_check_interval
@@ -1912,6 +1926,9 @@ def should_update_connection(
19121926
address_type_to_match: Literal["connected", "configured"] = "connected",
19131927
matching_address: Optional[str] = None,
19141928
) -> bool:
1929+
"""
1930+
Check if the connection should be updated based on the matching address.
1931+
"""
19151932
if address_type_to_match == "connected":
19161933
if matching_address and conn.getpeername() != matching_address:
19171934
return False
@@ -1964,6 +1981,7 @@ def update_connections_settings(
19641981
:param address_type_to_match: The type of address to match.
19651982
:param reset_host_address: Whether to reset the host address to the original address.
19661983
:param reset_relax_timeout: Whether to reset the relax timeout to the original timeout.
1984+
:param include_free_connections: Whether to include free/available connections.
19671985
"""
19681986
for conn in self._in_use_connections:
19691987
if self.should_update_connection(
@@ -2016,6 +2034,7 @@ def update_active_connections_for_reconnect(
20162034
20172035
:param tmp_host_address: The temporary host address to use for the connection.
20182036
:param tmp_relax_timeout: The relax timeout to use for the connection.
2037+
:param moving_address_src: The address of the node that is being moved.
20192038
"""
20202039
for conn in self._in_use_connections:
20212040
if self.should_update_connection(conn, "connected", moving_address_src):
@@ -2035,8 +2054,9 @@ def disconnect_and_reconfigure_free_connections(
20352054
20362055
When this method is called the pool will already be locked, so getting the pool lock inside is not needed.
20372056
2038-
:param orig_host_address: The temporary host address to use for the connection.
2039-
:param orig_relax_timeout: The relax timeout to use for the connection.
2057+
:param tmp_host_address: The temporary host address to use for the connection.
2058+
:param tmp_relax_timeout: The relax timeout to use for the connection.
2059+
:param moving_address_src: The address of the node that is being moved.
20402060
"""
20412061

20422062
for conn in self._available_connections:
@@ -2361,6 +2381,7 @@ def update_active_connections_for_reconnect(
23612381
23622382
:param tmp_host_address: The temporary host address to use for the connection.
23632383
:param tmp_relax_timeout: The relax timeout to use for the connection.
2384+
:param moving_address_src: The address of the node that is being moved.
23642385
"""
23652386
with self._lock:
23662387
connections_in_queue = {conn for conn in self.pool.queue if conn}
@@ -2386,6 +2407,7 @@ def disconnect_and_reconfigure_free_connections(
23862407
23872408
:param tmp_host_address: The temporary host address to use for the connection.
23882409
:param tmp_relax_timeout: The relax timeout to use for the connection.
2410+
:param moving_address_src: The address of the node that is being moved.
23892411
"""
23902412
existing_connections = self.pool.queue
23912413

0 commit comments

Comments
 (0)