@@ -159,22 +159,28 @@ async def read_response(
159159
160160
161161_INVALIDATION_MESSAGE = [b"invalidate" , "invalidate" ]
162+ _MOVING_MESSAGE = [b"MOVING" , "MOVING" ]
162163
163164
164165class PushNotificationsParser (Protocol ):
165166 """Protocol defining RESP3-specific parsing functionality"""
166167
167168 pubsub_push_handler_func : Callable
168169 invalidation_push_handler_func : Optional [Callable ] = None
170+ node_replacement_push_handler_func : Optional [Callable ] = None
169171
170172 def handle_pubsub_push_response (self , response ):
171173 """Handle pubsub push responses"""
172174 raise NotImplementedError ()
173175
174176 def handle_push_response (self , response , ** kwargs ):
175- if response [0 ] not in _INVALIDATION_MESSAGE :
177+ msg_type = response [0 ]
178+ if msg_type not in _INVALIDATION_MESSAGE and msg_type not in _MOVING_MESSAGE :
176179 return self .pubsub_push_handler_func (response )
177- if self .invalidation_push_handler_func :
180+ if msg_type in _MOVING_MESSAGE and self .node_replacement_push_handler_func :
181+ # push notification for enterprise cluster node replacement
182+ return self .node_replacement_push_handler_func (response )
183+ if msg_type in _INVALIDATION_MESSAGE and self .invalidation_push_handler_func :
178184 return self .invalidation_push_handler_func (response )
179185
180186 def set_pubsub_push_handler (self , pubsub_push_handler_func ):
@@ -183,22 +189,32 @@ def set_pubsub_push_handler(self, pubsub_push_handler_func):
183189 def set_invalidation_push_handler (self , invalidation_push_handler_func ):
184190 self .invalidation_push_handler_func = invalidation_push_handler_func
185191
192+ def set_node_replacement_push_handler_func (
193+ self , node_replacement_push_handler_func
194+ ):
195+ self .node_replacement_push_handler_func = node_replacement_push_handler_func
196+
186197
187198class AsyncPushNotificationsParser (Protocol ):
188199 """Protocol defining async RESP3-specific parsing functionality"""
189200
190201 pubsub_push_handler_func : Callable
191202 invalidation_push_handler_func : Optional [Callable ] = None
203+ node_replacement_push_handler_func : Optional [Callable ] = None
192204
193205 async def handle_pubsub_push_response (self , response ):
194206 """Handle pubsub push responses asynchronously"""
195207 raise NotImplementedError ()
196208
197209 async def handle_push_response (self , response , ** kwargs ):
198210 """Handle push responses asynchronously"""
199- if response [0 ] not in _INVALIDATION_MESSAGE :
211+ msg_type = response [0 ]
212+ if msg_type not in _INVALIDATION_MESSAGE and msg_type not in _MOVING_MESSAGE :
200213 return await self .pubsub_push_handler_func (response )
201- if self .invalidation_push_handler_func :
214+ if msg_type in _MOVING_MESSAGE and self .node_replacement_push_handler_func :
215+ # push notification for enterprise cluster node replacement
216+ return await self .node_replacement_push_handler_func (response )
217+ if msg_type in _INVALIDATION_MESSAGE and self .invalidation_push_handler_func :
202218 return await self .invalidation_push_handler_func (response )
203219
204220 def set_pubsub_push_handler (self , pubsub_push_handler_func ):
@@ -209,6 +225,11 @@ def set_invalidation_push_handler(self, invalidation_push_handler_func):
209225 """Set the invalidation push handler function"""
210226 self .invalidation_push_handler_func = invalidation_push_handler_func
211227
228+ def set_node_replacement_push_handler_func (
229+ self , node_replacement_push_handler_func
230+ ):
231+ self .node_replacement_push_handler_func = node_replacement_push_handler_func
232+
212233
213234class _AsyncRESPBase (AsyncBaseParser ):
214235 """Base class for async resp parsing"""
0 commit comments