@@ -241,6 +241,18 @@ def set_re_auth_token(self, token: TokenInterface):
241241 def re_auth (self ):
242242 pass
243243
244+ @abstractmethod
245+ def mark_for_reconnect (self ):
246+ pass
247+
248+ @abstractmethod
249+ def should_reconnect (self ):
250+ pass
251+
252+ @abstractmethod
253+ def reset_should_reconnect (self ):
254+ pass
255+
244256
245257class MaintNotificationsAbstractConnection :
246258 """
@@ -290,7 +302,6 @@ def __init__(
290302 orig_socket_connect_timeout ,
291303 parser ,
292304 )
293- self ._should_reconnect = False
294305
295306 @abstractmethod
296307 def _get_parser (self ) -> Union [_HiredisParser , _RESP3Parser ]:
@@ -590,15 +601,6 @@ def getpeername(self):
590601 return conn_socket .getpeername ()[0 ]
591602 return None
592603
593- def mark_for_reconnect (self ):
594- self ._should_reconnect = True
595-
596- def should_reconnect (self ):
597- return self ._should_reconnect
598-
599- def reset_should_reconnect (self ):
600- self ._should_reconnect = False
601-
602604 def update_current_socket_timeout (self , relaxed_timeout : Optional [float ] = None ):
603605 conn_socket = self ._get_socket ()
604606 if conn_socket :
@@ -758,6 +760,7 @@ def __init__(
758760 self .set_parser (parser_class )
759761
760762 self ._command_packer = self ._construct_command_packer (command_packer )
763+ self ._should_reconnect = False
761764
762765 # Set up maintenance notifications
763766 MaintNotificationsAbstractConnection .__init__ (
@@ -1023,6 +1026,15 @@ def disconnect(self, *args):
10231026 except OSError :
10241027 pass
10251028
1029+ def mark_for_reconnect (self ):
1030+ self ._should_reconnect = True
1031+
1032+ def should_reconnect (self ):
1033+ return self ._should_reconnect
1034+
1035+ def reset_should_reconnect (self ):
1036+ self ._should_reconnect = False
1037+
10261038 def _send_ping (self ):
10271039 """Send PING, expect PONG in return"""
10281040 self .send_command ("PING" , check_health = False )
@@ -1507,6 +1519,15 @@ def set_re_auth_token(self, token: TokenInterface):
15071519 def re_auth (self ):
15081520 self ._conn .re_auth ()
15091521
1522+ def mark_for_reconnect (self ):
1523+ self ._conn .mark_for_reconnect ()
1524+
1525+ def should_reconnect (self ):
1526+ return self ._conn .should_reconnect ()
1527+
1528+ def reset_should_reconnect (self ):
1529+ self ._conn .reset_should_reconnect ()
1530+
15101531 @property
15111532 def host (self ) -> str :
15121533 return self ._conn .host
@@ -1565,30 +1586,6 @@ def getpeername(self):
15651586 "Maintenance notifications are not supported by this connection type"
15661587 )
15671588
1568- def mark_for_reconnect (self ):
1569- if isinstance (self ._conn , MaintNotificationsAbstractConnection ):
1570- self ._conn .mark_for_reconnect ()
1571- else :
1572- raise NotImplementedError (
1573- "Maintenance notifications are not supported by this connection type"
1574- )
1575-
1576- def should_reconnect (self ):
1577- if isinstance (self ._conn , MaintNotificationsAbstractConnection ):
1578- return self ._conn .should_reconnect ()
1579- else :
1580- raise NotImplementedError (
1581- "Maintenance notifications are not supported by this connection type"
1582- )
1583-
1584- def reset_should_reconnect (self ):
1585- if isinstance (self ._conn , MaintNotificationsAbstractConnection ):
1586- self ._conn .reset_should_reconnect ()
1587- else :
1588- raise NotImplementedError (
1589- "Maintenance notifications are not supported by this connection type"
1590- )
1591-
15921589 def get_resolved_ip (self ):
15931590 if isinstance (self ._conn , MaintNotificationsAbstractConnection ):
15941591 return self ._conn .get_resolved_ip ()
0 commit comments