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

Fix restore command #468

Merged
merged 7 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions iredis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import os
import sys
import codecs
import logging
from subprocess import run
from importlib_resources import read_text
Expand Down Expand Up @@ -282,6 +283,7 @@ def execute_by_connection(self, connection, command_name, *args, **options):
connection.connect()
logger.info(f"New connection created, retry on {connection}.")
logger.info(f"send_command: {command_name} , {args}")

connection.send_command(command_name, *args)
response = connection.read_response()
except AuthenticationError:
Expand Down Expand Up @@ -547,6 +549,12 @@ def pre_hook(self, command, command_name, args, completer: IRedisCompleter):
if command_name.upper() in ["ZSCAN", "ZPOPMAX", "ZPOPMIN"]:
config.withscores = True

# TODO should we using escape_decode on all strings??
if command_name.upper() == "RESTORE":
for i, a in enumerate(args):
serialized_value = codecs.escape_decode(a)[0]
args[i] = serialized_value

# not a tty
if not completer:
logger.warning(
Expand Down
6 changes: 6 additions & 0 deletions tests/cli_tests/test_command_restore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def test_restore_command(clean_redis, cli):
cli.sendline(r'restore foo1 0 "\x00\x03bar\t\x006L\x18\xac\xba\xe0\x9e\xa6"')
cli.expect(["OK", "127.0.0.1"])

cli.sendline("get foo1")
cli.expect('"bar"')
2 changes: 1 addition & 1 deletion tests/unittests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def test_peek_set_fetch_part(iredis_client, clean_redis):
peek_result = list(iredis_client.do_peek("myset"))

assert peek_result[0][0] == ("class:dockey", "key: ")
assert peek_result[0][1][1].startswith("set (hashtable) mem: 2")
assert peek_result[0][1][1].startswith("set (hashtable) mem: ")


def test_peek_zset_fetch_all(iredis_client, clean_redis):
Expand Down
Loading