1
- import copy
2
1
import random
3
2
import weakref
4
3
5
- from redis .backoff import NoBackoff
6
4
from redis .client import Redis
7
5
from redis .commands import SentinelCommands
8
6
from redis .connection import Connection , ConnectionPool , SSLConnection
9
7
from redis .exceptions import ConnectionError , ReadOnlyError , ResponseError , TimeoutError
10
- from redis .retry import Retry
11
8
from redis .utils import str_if_bytes
12
9
13
10
@@ -40,7 +37,7 @@ def connect_to(self, address):
40
37
if str_if_bytes (self .read_response ()) != "PONG" :
41
38
raise ConnectionError ("PING failed" )
42
39
43
- def connect (self ):
40
+ def _connect_retry (self ):
44
41
if self ._sock :
45
42
return # already connected
46
43
if self .connection_pool .is_master :
@@ -53,6 +50,12 @@ def connect(self):
53
50
continue
54
51
raise SlaveNotFoundError # Never be here
55
52
53
+ def connect (self ):
54
+ return self .retry .call_with_retry (
55
+ self ._connect_retry ,
56
+ lambda error : None ,
57
+ )
58
+
56
59
def read_response (self , disable_decoding = False ):
57
60
try :
58
61
return super ().read_response (disable_decoding = disable_decoding )
@@ -87,24 +90,6 @@ def __init__(self, service_name, sentinel_manager, **kwargs):
87
90
if kwargs .pop ("ssl" , False )
88
91
else SentinelManagedConnection ,
89
92
)
90
- retry = kwargs .get ("retry" , None )
91
- retry_on_error = kwargs .get ("retry_on_error" , None )
92
- retry_on_timeout = kwargs .get ("retry_on_timeout" , False )
93
- self .retry_on_timeout = retry_on_timeout
94
- if retry_on_timeout :
95
- # Add TimeoutError to the errors list to retry on
96
- retry_on_error .append (TimeoutError )
97
- self .retry_on_error = retry_on_error
98
- if retry_on_error :
99
- if retry is None :
100
- self .retry = Retry (NoBackoff (), 1 )
101
- else :
102
- # deep-copy the Retry object as it is mutable
103
- self .retry = copy .deepcopy (retry )
104
- # Update the retry's supported errors with the specified errors
105
- self .retry .update_supported_erros (retry_on_error )
106
- else :
107
- self .retry = Retry (NoBackoff (), 0 )
108
93
self .is_master = kwargs .pop ("is_master" , True )
109
94
self .check_connection = kwargs .pop ("check_connection" , False )
110
95
super ().__init__ (** kwargs )
@@ -128,12 +113,6 @@ def owns_connection(self, connection):
128
113
parent = super ()
129
114
return check and parent .owns_connection (connection )
130
115
131
- def get_connection (self , * args , ** kwargs ):
132
- return self .retry .call_with_retry (
133
- lambda : super (type (self ), self ).get_connection (self , * args , ** kwargs ),
134
- lambda error : None ,
135
- )
136
-
137
116
def get_master_address (self ):
138
117
master_address = self .sentinel_manager .discover_master (self .service_name )
139
118
if self .is_master :
0 commit comments