-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Client side caching invalidations (standalone) #3089
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ac282f2
cache invalidations
dvora-h 5638acb
isort
dvora-h 494d1bc
deamon thread
dvora-h 3cf4f14
remove threads
dvora-h e5f2bba
delete comment
dvora-h 455e894
tests
dvora-h 814f78a
skip if hiredis available
dvora-h 8dc575e
async
dvora-h da92402
review comments
dvora-h 8fe83ab
docstring
dvora-h a9965b2
decode test
dvora-h f908954
fix test
dvora-h 5fd31c7
fix decode response test
dvora-h File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,18 @@ | |
from .base import _AsyncRESPBase, _RESPBase | ||
from .socket import SERVER_CLOSED_CONNECTION_ERROR | ||
|
||
_INVALIDATION_MESSAGE = [b"invalidate", "invalidate"] | ||
|
||
|
||
class _RESP3Parser(_RESPBase): | ||
"""RESP3 protocol implementation""" | ||
|
||
def __init__(self, socket_read_size): | ||
super().__init__(socket_read_size) | ||
self.push_handler_func = self.handle_push_response | ||
self.pubsub_push_handler_func = self.handle_pubsub_push_response | ||
self.invalidations_push_handler_func = None | ||
|
||
def handle_push_response(self, response): | ||
def handle_pubsub_push_response(self, response): | ||
logger = getLogger("push_response") | ||
logger.info("Push response: " + str(response)) | ||
return response | ||
|
@@ -114,30 +117,40 @@ def _read_response(self, disable_decoding=False, push_request=False): | |
) | ||
for _ in range(int(response)) | ||
] | ||
res = self.push_handler_func(response) | ||
if not push_request: | ||
return self._read_response( | ||
disable_decoding=disable_decoding, push_request=push_request | ||
) | ||
else: | ||
return res | ||
self.handle_push_response(response, disable_decoding, push_request) | ||
else: | ||
raise InvalidResponse(f"Protocol Error: {raw!r}") | ||
|
||
if isinstance(response, bytes) and disable_decoding is False: | ||
response = self.encoder.decode(response) | ||
return response | ||
|
||
def set_push_handler(self, push_handler_func): | ||
self.push_handler_func = push_handler_func | ||
def handle_push_response(self, response, disable_decoding, push_request): | ||
if response[0] in _INVALIDATION_MESSAGE: | ||
res = self.invalidation_push_handler_func(response) | ||
else: | ||
res = self.pubsub_push_handler_func(response) | ||
if not push_request: | ||
return self._read_response( | ||
disable_decoding=disable_decoding, push_request=push_request | ||
) | ||
else: | ||
return res | ||
|
||
def set_pubsub_push_handler(self, pubsub_push_handler_func): | ||
chayim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.pubsub_push_handler_func = pubsub_push_handler_func | ||
|
||
def set_invalidation_push_handler(self, invalidations_push_handler_func): | ||
chayim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.invalidation_push_handler_func = invalidations_push_handler_func | ||
|
||
|
||
class _AsyncRESP3Parser(_AsyncRESPBase): | ||
def __init__(self, socket_read_size): | ||
super().__init__(socket_read_size) | ||
self.push_handler_func = self.handle_push_response | ||
self.pubsub_push_handler_func = self.handle_pubsub_push_response | ||
self.invalidations_push_handler_func = None | ||
|
||
def handle_push_response(self, response): | ||
def handle_pubsub_push_response(self, response): | ||
logger = getLogger("push_response") | ||
logger.info("Push response: " + str(response)) | ||
return response | ||
|
@@ -246,19 +259,28 @@ async def _read_response( | |
) | ||
for _ in range(int(response)) | ||
] | ||
res = self.push_handler_func(response) | ||
if not push_request: | ||
return await self._read_response( | ||
disable_decoding=disable_decoding, push_request=push_request | ||
) | ||
else: | ||
return res | ||
await self.handle_push_response(response, disable_decoding, push_request) | ||
else: | ||
raise InvalidResponse(f"Protocol Error: {raw!r}") | ||
|
||
if isinstance(response, bytes) and disable_decoding is False: | ||
response = self.encoder.decode(response) | ||
return response | ||
|
||
def set_push_handler(self, push_handler_func): | ||
self.push_handler_func = push_handler_func | ||
async def handle_push_response(self, response, disable_decoding, push_request): | ||
if response[0] in _INVALIDATION_MESSAGE: | ||
res = self.invalidation_push_handler_func(response) | ||
else: | ||
res = self.pubsub_push_handler_func(response) | ||
if not push_request: | ||
return await self._read_response( | ||
disable_decoding=disable_decoding, push_request=push_request | ||
) | ||
else: | ||
return res | ||
Comment on lines
+270
to
+280
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. confused why this logic seems to be duplicated from above? |
||
|
||
def set_pubsub_push_handler(self, pubsub_push_handler_func): | ||
chayim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.pubsub_push_handler_func = pubsub_push_handler_func | ||
|
||
def set_invalidation_push_handler(self, invalidations_push_handler_func): | ||
chayim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.invalidation_push_handler_func = invalidations_push_handler_func |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it be better to test response[0] for pubsub as well (think its "message"?) and error out if its another type not supported.
if willing to force python 3.10, can use a switch/case/default stateent?
don't understand what pust_request is yet.