Skip to content

Commit

Permalink
Fix invalidations push handler in RESP3
Browse files Browse the repository at this point in the history
  • Loading branch information
gerzse committed Jun 19, 2024
1 parent c518bb4 commit 2a9f95d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions redis/_parsers/resp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class _RESP3Parser(_RESPBase):
def __init__(self, socket_read_size):
super().__init__(socket_read_size)
self.pubsub_push_handler_func = self.handle_pubsub_push_response
self.invalidations_push_handler_func = None
self.invalidation_push_handler_func = None

def handle_pubsub_push_response(self, response):
logger = getLogger("push_response")
Expand Down Expand Up @@ -129,7 +129,10 @@ def _read_response(self, disable_decoding=False, push_request=False):

def handle_push_response(self, response, disable_decoding, push_request):
if response[0] in _INVALIDATION_MESSAGE:
res = self.invalidation_push_handler_func(response)
if self.invalidation_push_handler_func:
res = self.invalidation_push_handler_func(response)
else:
res = None
else:
res = self.pubsub_push_handler_func(response)
if not push_request:
Expand All @@ -142,15 +145,15 @@ def handle_push_response(self, response, disable_decoding, push_request):
def set_pubsub_push_handler(self, pubsub_push_handler_func):
self.pubsub_push_handler_func = pubsub_push_handler_func

def set_invalidation_push_handler(self, invalidations_push_handler_func):
self.invalidation_push_handler_func = invalidations_push_handler_func
def set_invalidation_push_handler(self, invalidation_push_handler_func):
self.invalidation_push_handler_func = invalidation_push_handler_func


class _AsyncRESP3Parser(_AsyncRESPBase):
def __init__(self, socket_read_size):
super().__init__(socket_read_size)
self.pubsub_push_handler_func = self.handle_pubsub_push_response
self.invalidations_push_handler_func = None
self.invalidation_push_handler_func = None

def handle_pubsub_push_response(self, response):
logger = getLogger("push_response")
Expand Down Expand Up @@ -273,7 +276,10 @@ async def _read_response(

async def handle_push_response(self, response, disable_decoding, push_request):
if response[0] in _INVALIDATION_MESSAGE:
res = self.invalidation_push_handler_func(response)
if self.invalidation_push_handler_func:
res = self.invalidation_push_handler_func(response)
else:
res = None
else:
res = self.pubsub_push_handler_func(response)
if not push_request:
Expand All @@ -286,5 +292,5 @@ async def handle_push_response(self, response, disable_decoding, push_request):
def set_pubsub_push_handler(self, pubsub_push_handler_func):
self.pubsub_push_handler_func = pubsub_push_handler_func

def set_invalidation_push_handler(self, invalidations_push_handler_func):
self.invalidation_push_handler_func = invalidations_push_handler_func
def set_invalidation_push_handler(self, invalidation_push_handler_func):
self.invalidation_push_handler_func = invalidation_push_handler_func

0 comments on commit 2a9f95d

Please sign in to comment.