-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Support RESP3 with hiredis-py parser #3648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
fa1f654
176baa8
e45207f
01edcdd
0dd887e
d3cbd6f
0b3ac2b
1b5ea1b
3e71752
0160963
f52786f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,16 @@ | |
|
||
from ..exceptions import ConnectionError, InvalidResponse, ResponseError | ||
from ..typing import EncodableT | ||
from .base import _AsyncRESPBase, _RESPBase | ||
from .base import ( | ||
AsyncPushNotificationsParser, | ||
PushNotificationsParser, | ||
_AsyncRESPBase, | ||
_RESPBase, | ||
) | ||
from .socket import SERVER_CLOSED_CONNECTION_ERROR | ||
|
||
_INVALIDATION_MESSAGE = [b"invalidate", "invalidate"] | ||
|
||
|
||
class _RESP3Parser(_RESPBase): | ||
class _RESP3Parser(_RESPBase, PushNotificationsParser): | ||
"""RESP3 protocol implementation""" | ||
|
||
def __init__(self, socket_read_size): | ||
|
@@ -113,9 +116,7 @@ def _read_response(self, disable_decoding=False, push_request=False): | |
) | ||
for _ in range(int(response)) | ||
] | ||
response = self.handle_push_response( | ||
response, disable_decoding, push_request | ||
) | ||
response = self.handle_push_response(response) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The updated handle_push_response signature no longer accepts disable_decoding and push_request parameters, which deviates from a typical protocol interface. If intentional, please update the documentation to clearly describe the new behavior. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
if not push_request: | ||
return self._read_response( | ||
disable_decoding=disable_decoding, push_request=push_request | ||
|
@@ -129,20 +130,8 @@ def _read_response(self, disable_decoding=False, push_request=False): | |
response = self.encoder.decode(response) | ||
return response | ||
|
||
def handle_push_response(self, response, disable_decoding, push_request): | ||
if response[0] not in _INVALIDATION_MESSAGE: | ||
return self.pubsub_push_handler_func(response) | ||
if self.invalidation_push_handler_func: | ||
return self.invalidation_push_handler_func(response) | ||
|
||
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, invalidation_push_handler_func): | ||
self.invalidation_push_handler_func = invalidation_push_handler_func | ||
|
||
|
||
class _AsyncRESP3Parser(_AsyncRESPBase): | ||
class _AsyncRESP3Parser(_AsyncRESPBase, AsyncPushNotificationsParser): | ||
def __init__(self, socket_read_size): | ||
super().__init__(socket_read_size) | ||
self.pubsub_push_handler_func = self.handle_pubsub_push_response | ||
|
@@ -253,9 +242,7 @@ async def _read_response( | |
) | ||
for _ in range(int(response)) | ||
] | ||
response = await self.handle_push_response( | ||
response, disable_decoding, push_request | ||
) | ||
response = await self.handle_push_response(response) | ||
if not push_request: | ||
return await self._read_response( | ||
disable_decoding=disable_decoding, push_request=push_request | ||
|
@@ -268,15 +255,3 @@ async def _read_response( | |
if isinstance(response, bytes) and disable_decoding is False: | ||
response = self.encoder.decode(response) | ||
return response | ||
|
||
async def handle_push_response(self, response, disable_decoding, push_request): | ||
if response[0] not in _INVALIDATION_MESSAGE: | ||
return await self.pubsub_push_handler_func(response) | ||
if self.invalidation_push_handler_func: | ||
return await self.invalidation_push_handler_func(response) | ||
|
||
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, invalidation_push_handler_func): | ||
self.invalidation_push_handler_func = invalidation_push_handler_func |
Uh oh!
There was an error while loading. Please reload this page.