Skip to content
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

Works around the limitations to support dump in the ugliest way possible #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions interwebz/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def _parse_command_response(self, response, **options):

for c in self.commands.keys():
# make sure all responses will be returned as is
self.set_response_callback(c, lambda res: res)
self.set_response_callback(c, lambda res, **options: res)

def _get_commands(self):
self.set_response_callback('COMMAND', self._parse_command_response)
Expand Down Expand Up @@ -210,6 +210,11 @@ def execute_namespaced(self, session: PageSession, argv: list) -> Any:
# TODO: patterns may be extracted the from command arguments pecs, and if so
# we can add support for `SORT` and potential future commands automatically.
cmd = self.commands[cmd_name]
options = {}
if cmd_name == 'dump':
from redis.client import NEVER_DECODE
options[NEVER_DECODE] = []

if cmd_name == 'keys' and argc == 2:
# Namespace the key pattern
argv[1] = f'{session}:{argv[1]}'
Expand Down Expand Up @@ -251,7 +256,7 @@ def execute_namespaced(self, session: PageSession, argv: list) -> Any:
argv[i] = f'{session}:{argv[i]}'

# Send the command
rep = self.execute_command(*argv)
rep = self.execute_command(*argv, **options)

# Post-processin'
if cmd_name == 'keys':
Expand All @@ -260,5 +265,7 @@ def execute_namespaced(self, session: PageSession, argv: list) -> Any:
rep[1] = self._strip_id_from_keys(session, rep[1])
elif cmd_name in ['lmpop','zmpop'] and rep is not None and len(rep) == 2:
rep[0] = self._strip_id_from_keys(session, [rep[0]])[0]
elif cmd_name == 'dump':
rep = repr(rep)[2:-1]

return rep