22from typing import TYPE_CHECKING , Any , Awaitable , Callable , Tuple , Type , TypeVar
33
44from redis .exceptions import ConnectionError , RedisError , TimeoutError
5-
6- if TYPE_CHECKING :
7- from redis .backoff import AbstractBackoff
8-
5+ from redis .retry import AbstractRetry
96
107T = TypeVar ("T" )
118
9+ if TYPE_CHECKING :
10+ from redis .backoff import AbstractBackoff
1211
13- class Retry :
14- """Retry a specific number of times after a failure"""
1512
16- __slots__ = "_backoff" , "_retries" , "_supported_errors"
13+ class Retry (AbstractRetry [RedisError ]):
14+ __hash__ = AbstractRetry .__hash__
1715
1816 def __init__ (
1917 self ,
@@ -24,36 +22,17 @@ def __init__(
2422 TimeoutError ,
2523 ),
2624 ):
27- """
28- Initialize a `Retry` object with a `Backoff` object
29- that retries a maximum of `retries` times.
30- `retries` can be negative to retry forever.
31- You can specify the types of supported errors which trigger
32- a retry with the `supported_errors` parameter.
33- """
34- self ._backoff = backoff
35- self ._retries = retries
36- self ._supported_errors = supported_errors
25+ super ().__init__ (backoff , retries , supported_errors )
3726
38- def update_supported_errors (self , specified_errors : list ):
39- """
40- Updates the supported errors with the specified error types
41- """
42- self ._supported_errors = tuple (
43- set (self ._supported_errors + tuple (specified_errors ))
44- )
45-
46- def get_retries (self ) -> int :
47- """
48- Get the number of retries.
49- """
50- return self ._retries
27+ def __eq__ (self , other : Any ) -> bool :
28+ if not isinstance (other , Retry ):
29+ return NotImplemented
5130
52- def update_retries ( self , value : int ) -> None :
53- """
54- Set the number of retries.
55- """
56- self . _retries = value
31+ return (
32+ self . _backoff == other . _backoff
33+ and self . _retries == other . _retries
34+ and set ( self . _supported_errors ) == set ( other . _supported_errors )
35+ )
5736
5837 async def call_with_retry (
5938 self , do : Callable [[], Awaitable [T ]], fail : Callable [[RedisError ], Any ]
0 commit comments