diff --git a/redis/_parsers/base.py b/redis/_parsers/base.py index 69d7b585dd..9fe77bcd3b 100644 --- a/redis/_parsers/base.py +++ b/redis/_parsers/base.py @@ -1,7 +1,17 @@ +import logging import sys from abc import ABC from asyncio import IncompleteReadError, StreamReader, TimeoutError -from typing import Callable, List, Optional, Protocol, Union +from typing import Awaitable, Callable, List, Optional, Protocol, Union + +from redis.maintenance_events import ( + MaintenanceEvent, + NodeFailedOverEvent, + NodeFailingOverEvent, + NodeMigratedEvent, + NodeMigratingEvent, + NodeMovingEvent, +) if sys.version_info.major >= 3 and sys.version_info.minor >= 11: from asyncio import timeout as async_timeout @@ -50,6 +60,8 @@ "Client sent AUTH, but no password is set": AuthenticationError, } +logger = logging.getLogger(__name__) + class BaseParser(ABC): EXCEPTION_CLASSES = { @@ -158,7 +170,75 @@ async def read_response( raise NotImplementedError() -_INVALIDATION_MESSAGE = [b"invalidate", "invalidate"] +class MaintenanceNotificationsParser: + """Protocol defining maintenance push notification parsing functionality""" + + @staticmethod + def parse_maintenance_start_msg(response, notification_type): + # Expected message format is: