Skip to content

Commit c00ac73

Browse files
committed
Applying review comments.
1 parent c1adf67 commit c00ac73

File tree

8 files changed

+34
-34
lines changed

8 files changed

+34
-34
lines changed

docs/retry.rst

+1-7
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,11 @@ Retry in Redis Cluster
4949
Retry behaviour in Redis Cluster is a little bit different from Standalone:
5050

5151
* ``retry``: :class:`~.Retry` instance with a :ref:`backoff-label` strategy and the max number of retries, default value is ``Retry(ExponentialWithJitterBackoff(base=1, cap=10), cluster_error_retry_attempts)``
52-
* ``cluster_error_retry_attempts``: number of times to retry before raising an error when :class:`~.TimeoutError` or :class:`~.ConnectionError` or :class:`~.ClusterDownError` or :class:`~.SlotNotCoveredError` are encountered, default value is ``3``
52+
* ``cluster_error_retry_attempts``: number of times to retry before raising an error when :class:`~.TimeoutError`, :class:`~.ConnectionError`, :class:`~.ClusterDownError` or :class:`~.SlotNotCoveredError` are encountered, default value is ``3``
5353
* This argument is deprecated - it is used to initialize the number of retries for the retry object,
5454
only in the case when the ``retry`` object is not provided.
5555
When the ``retry`` argument is provided, the ``cluster_error_retry_attempts`` argument is ignored!
5656

57-
* Starting from version 6.0.0 of the library, the default retry policy for the nodes connections is without retries.
58-
This means that if a connection to a node fails, the lower level connection will not retry the connection.
59-
Instead, it will raise a :class:`~.ConnectionError` to the cluster level call., where it will be retried.
60-
This is done to avoid blocking the cluster client for too long in case of a node failure.
61-
6257
* The retry object is not yet fully utilized in the cluster client.
6358
The retry object is used only to determine the number of retries for the cluster level calls.
6459

@@ -74,6 +69,5 @@ Let's consider the following example:
7469
#. the client library calculates the hash slot for key 'foo'.
7570
#. given the hash slot, it then determines which node to connect to, in order to execute the command.
7671
#. during the connection, a :class:`~.ConnectionError` is raised.
77-
#. because the default retry policy for the nodes connections is without retries, the error is raised to the cluster level call
7872
#. because we set ``retry=Retry(ExponentialBackoff(), 6)``, the cluster client starts a cluster update, removes the failed node from the startup nodes, and re-initializes the cluster.
7973
#. the cluster client retries the command until it either succeeds or the max number of retries is reached.

redis/asyncio/cluster.py

-3
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,6 @@ def get_connection_kwargs(self) -> Dict[str, Optional[Any]]:
565565
"""Get the kwargs passed to :class:`~redis.asyncio.connection.Connection`."""
566566
return self.connection_kwargs
567567

568-
def get_retry(self) -> Retry:
569-
return self.retry
570-
571568
def set_retry(self, retry: Retry) -> None:
572569
if not isinstance(retry, Retry):
573570
raise TypeError(

redis/asyncio/retry.py

-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ def update_retries(self, value: int) -> None:
5353
"""
5454
Set the number of retries.
5555
"""
56-
if not isinstance(value, int):
57-
raise ValueError("Retries must be an integer.")
5856
self._retries = value
5957

6058
async def call_with_retry(

redis/cluster.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ def __init__(
610610
# and there we provide retry configuration without retries allowed.
611611
# The retries should be handled on cluster client level.
612612
raise RedisClusterException(
613-
"Argument 'retry' is not possible to be used in kwargs when in cluster mode"
613+
"The 'retry' argument cannot be used in kwargs when running in cluster mode."
614614
)
615615

616616
# Get the startup node/s
@@ -800,9 +800,6 @@ def set_default_node(self, node):
800800
self.nodes_manager.default_node = node
801801
return True
802802

803-
def get_retry(self) -> Retry:
804-
return self.retry
805-
806803
def set_retry(self, retry: Retry) -> None:
807804
if not isinstance(retry, Retry):
808805
raise TypeError("retry must be a valid instance of redis.retry.Retry")

redis/retry.py

-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ def update_retries(self, value: int) -> None:
5454
"""
5555
Set the number of retries.
5656
"""
57-
if not isinstance(value, int):
58-
raise ValueError("Retries count must be an integer.")
5957
self._retries = value
6058

6159
def call_with_retry(

tests/test_asyncio/test_cluster.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ async def test_cluster_set_get_retry_object(self, request: FixtureRequest):
371371
retry = Retry(NoBackoff(), 2)
372372
url = request.config.getoption("--redis-url")
373373
async with RedisCluster.from_url(url, retry=retry) as r:
374-
assert r.get_retry().get_retries() == retry.get_retries()
375-
assert isinstance(r.get_retry()._backoff, NoBackoff)
374+
assert r.retry.get_retries() == retry.get_retries()
375+
assert isinstance(r.retry._backoff, NoBackoff)
376376
for node in r.get_nodes():
377377
# validate nodes lower level connections default
378378
# retry policy is applied
@@ -385,8 +385,8 @@ async def test_cluster_set_get_retry_object(self, request: FixtureRequest):
385385
# Change retry policy
386386
new_retry = Retry(ExponentialBackoff(), 3)
387387
r.set_retry(new_retry)
388-
assert r.get_retry().get_retries() == new_retry.get_retries()
389-
assert isinstance(r.get_retry()._backoff, ExponentialBackoff)
388+
assert r.retry.get_retries() == new_retry.get_retries()
389+
assert isinstance(r.retry._backoff, ExponentialBackoff)
390390
for node in r.get_nodes():
391391
# validate nodes lower level connections are not affected
392392
n_retry = node.acquire_connection().retry
@@ -423,7 +423,7 @@ async def test_cluster_retry_object(self, request: FixtureRequest) -> None:
423423
retry = Retry(ExponentialBackoff(10, 5), 5)
424424
async with RedisCluster.from_url(url, retry=retry) as rc_custom_retry:
425425
# Test custom retry
426-
assert rc_custom_retry.get_retry() == retry
426+
assert rc_custom_retry.retry == retry
427427
# validate nodes connections are using the default retry for
428428
# lower level connections when client is created through 'from_url' method
429429
# with specified retry object
@@ -438,12 +438,12 @@ async def test_cluster_retry_object(self, request: FixtureRequest) -> None:
438438
url, cluster_error_retry_attempts=0
439439
) as rc_no_retries:
440440
# Test no cluster retries
441-
assert rc_no_retries.get_retry().get_retries() == 0
441+
assert rc_no_retries.retry.get_retries() == 0
442442

443443
async with RedisCluster.from_url(
444444
url, retry=Retry(NoBackoff(), 0)
445445
) as rc_no_retries:
446-
assert rc_no_retries.get_retry().get_retries() == 0
446+
assert rc_no_retries.retry.get_retries() == 0
447447

448448
async def test_empty_startup_nodes(self) -> None:
449449
"""

tests/test_cluster.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -888,8 +888,8 @@ def moved_redirect_effect(connection, *args, **options):
888888
def test_cluster_get_set_retry_object(self, request):
889889
retry = Retry(NoBackoff(), 2)
890890
r = _get_client(RedisCluster, request, retry=retry)
891-
assert r.get_retry().get_retries() == retry.get_retries()
892-
assert isinstance(r.get_retry()._backoff, NoBackoff)
891+
assert r.retry.get_retries() == retry.get_retries()
892+
assert isinstance(r.retry._backoff, NoBackoff)
893893
for node in r.get_nodes():
894894
assert node.redis_connection.get_retry().get_retries() == 0
895895
assert isinstance(node.redis_connection.get_retry()._backoff, NoBackoff)
@@ -898,8 +898,8 @@ def test_cluster_get_set_retry_object(self, request):
898898
# Change retry policy
899899
new_retry = Retry(ExponentialBackoff(), 3)
900900
r.set_retry(new_retry)
901-
assert r.get_retry().get_retries() == new_retry.get_retries()
902-
assert isinstance(r.get_retry()._backoff, ExponentialBackoff)
901+
assert r.retry.get_retries() == new_retry.get_retries()
902+
assert isinstance(r.retry._backoff, ExponentialBackoff)
903903
for node in r.get_nodes():
904904
assert node.redis_connection.get_retry()._retries == 0
905905
assert isinstance(node.redis_connection.get_retry()._backoff, NoBackoff)
@@ -913,14 +913,14 @@ def test_cluster_retry_object(self, r) -> None:
913913
host = r.get_default_node().host
914914

915915
# test default retry config
916-
retry = r.get_retry()
916+
retry = r.retry
917917
assert isinstance(retry, Retry)
918918
assert retry.get_retries() == 3
919919
assert isinstance(retry._backoff, type(ExponentialWithJitterBackoff()))
920-
node1 = r.get_node(host, 16379).redis_connection
921-
node2 = r.get_node(host, 16380).redis_connection
922-
assert node1.get_retry()._retries == 0
923-
assert node2.get_retry()._retries == 0
920+
node1_connection = r.get_node(host, 16379).redis_connection
921+
node2_connection = r.get_node(host, 16380).redis_connection
922+
assert node1_connection.get_retry()._retries == 0
923+
assert node2_connection.get_retry()._retries == 0
924924

925925
# Test custom retry is not applied to nodes
926926
retry = Retry(ExponentialBackoff(10, 5), 5)

tests/test_retry.py

+16
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,22 @@ def test_client_retry_on_timeout(self, request):
203203
finally:
204204
assert parse_response.call_count == retries + 1
205205

206+
@pytest.mark.onlycluster
207+
def test_get_set_retry_object_for_cluster_client(self, request):
208+
retry = Retry(NoBackoff(), 2)
209+
r = _get_client(Redis, request, retry_on_timeout=True, retry=retry)
210+
exist_conn = r.connection_pool.get_connection()
211+
assert r.retry._retries == retry._retries
212+
assert isinstance(r.retry._backoff, NoBackoff)
213+
new_retry_policy = Retry(ExponentialBackoff(), 3)
214+
r.set_retry(new_retry_policy)
215+
assert r.retry._retries == new_retry_policy._retries
216+
assert isinstance(r.retry._backoff, ExponentialBackoff)
217+
assert exist_conn.retry._retries == new_retry_policy._retries
218+
new_conn = r.connection_pool.get_connection()
219+
assert new_conn.retry._retries == new_retry_policy._retries
220+
221+
@pytest.mark.onlynoncluster
206222
def test_get_set_retry_object(self, request):
207223
retry = Retry(NoBackoff(), 2)
208224
r = _get_client(Redis, request, retry_on_timeout=True, retry=retry)

0 commit comments

Comments
 (0)