|
6 | 6 | from collections import OrderedDict
|
7 | 7 | from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
8 | 8 |
|
9 |
| -from redis.backoff import get_default_backoff |
| 9 | +from redis.backoff import default_backoff, NoBackoff |
10 | 10 | from redis.client import CaseInsensitiveDict, PubSub, Redis, parse_scan
|
11 | 11 | from redis.commands import READ_COMMANDS, CommandsParser, RedisClusterCommands
|
12 | 12 | from redis.connection import ConnectionPool, DefaultParser, Encoder, parse_url
|
@@ -430,9 +430,7 @@ def __init__(
|
430 | 430 | port: int = 6379,
|
431 | 431 | startup_nodes: Optional[List["ClusterNode"]] = None,
|
432 | 432 | cluster_error_retry_attempts: int = 3,
|
433 |
| - connection_error_retry_attempts: int = 3, |
434 | 433 | retry: Optional["Retry"] = None,
|
435 |
| - retry_on_error: Optional[List[Exception]] = None, |
436 | 434 | require_full_coverage: bool = False,
|
437 | 435 | reinitialize_steps: int = 10,
|
438 | 436 | read_from_replicas: bool = False,
|
@@ -476,13 +474,7 @@ def __init__(
|
476 | 474 | Number of times to retry before raising an error when
|
477 | 475 | :class:`~.TimeoutError` or :class:`~.ConnectionError` or
|
478 | 476 | :class:`~.ClusterDownError` are encountered
|
479 |
| - :param connection_error_retry_attempts: |
480 |
| - Number of times to retry before reinitializing when :class:`~.TimeoutError` |
481 |
| - or :class:`~.ConnectionError` are encountered. |
482 |
| - The default backoff strategy will be set if Retry object is not passed (see |
483 |
| - get_default_backoff in backoff.py). To change it, pass a custom Retry object |
484 |
| - using the "retry" keyword. |
485 |
| - :reinitialize_steps: 'int' |
| 477 | + :param reinitialize_steps: |
486 | 478 | Specifies the number of MOVED errors that need to occur before
|
487 | 479 | reinitializing the whole cluster topology. If a MOVED error occurs
|
488 | 480 | and the cluster does not need to be reinitialized on this current
|
@@ -550,17 +542,11 @@ def __init__(
|
550 | 542 | self.user_on_connect_func = kwargs.pop("redis_connect_func", None)
|
551 | 543 | kwargs.update({"redis_connect_func": self.on_connect})
|
552 | 544 | kwargs = cleanup_kwargs(**kwargs)
|
553 |
| - |
554 |
| - if retry or retry_on_error or connection_error_retry_attempts > 0: |
555 |
| - # Set a retry object for all cluster nodes |
556 |
| - self.retry = retry or Retry( |
557 |
| - get_default_backoff(), connection_error_retry_attempts |
558 |
| - ) |
559 |
| - if retry_on_error is None: |
560 |
| - # Default errors for retrying |
561 |
| - retry_on_error = [ConnectionError, TimeoutError] |
562 |
| - self.retry.update_supported_errors(retry_on_error) |
| 545 | + if retry: |
| 546 | + self.retry = retry |
563 | 547 | kwargs.update({"retry": self.retry})
|
| 548 | + else: |
| 549 | + kwargs.update({"retry": Retry(default_backoff(), 0)}) |
564 | 550 |
|
565 | 551 | self.encoder = Encoder(
|
566 | 552 | kwargs.get("encoding", "utf-8"),
|
@@ -1019,7 +1005,9 @@ def execute_command(self, *args, **kwargs):
|
1019 | 1005 | retry_attempts = (
|
1020 | 1006 | 0 if target_nodes_specified else self.cluster_error_retry_attempts
|
1021 | 1007 | )
|
1022 |
| - while True: |
| 1008 | + # Add one for the first execution |
| 1009 | + execute_attempts = 1 + retry_attempts |
| 1010 | + for _ in range(execute_attempts): |
1023 | 1011 | try:
|
1024 | 1012 | res = {}
|
1025 | 1013 | if not target_nodes_specified:
|
|
0 commit comments