From dadcc5988fb95f570fe092ccab5bea0cef26bc28 Mon Sep 17 00:00:00 2001 From: Yann Hamon Date: Wed, 27 Dec 2023 14:53:26 +0100 Subject: [PATCH] Handle empty values (#49) --- pkg/redisdump/redisdump.go | 2 +- pkg/redisdump/redisdump_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/redisdump/redisdump.go b/pkg/redisdump/redisdump.go index d889342..bb5ef85 100644 --- a/pkg/redisdump/redisdump.go +++ b/pkg/redisdump/redisdump.go @@ -127,7 +127,7 @@ func RedisCmdSerializer(cmd []string) string { buf := strings.Builder{} buf.WriteString(fmt.Sprintf("%s", cmd[0])) for i := 1; i < len(cmd); i++ { - if strings.Contains(cmd[i], " ") { + if strings.Contains(cmd[i], " ") || len(cmd[i]) == 0 { buf.WriteString(fmt.Sprintf(" \"%s\"", cmd[i])) } else { buf.WriteString(fmt.Sprintf(" %s", cmd[i])) diff --git a/pkg/redisdump/redisdump_test.go b/pkg/redisdump/redisdump_test.go index 1300fc3..64b1da5 100644 --- a/pkg/redisdump/redisdump_test.go +++ b/pkg/redisdump/redisdump_test.go @@ -214,6 +214,7 @@ func TestRedisCmdSerializer(t *testing.T) { {command: []string{"HELLO"}, expected: "HELLO"}, {command: []string{"HGETALL", "key"}, expected: "HGETALL key"}, {command: []string{"SET", "key name 1", "key value 1"}, expected: "SET \"key name 1\" \"key value 1\""}, + {command: []string{"SET", "key", ""}, expected: "SET key \"\""}, {command: []string{"HSET", "key1", "key value 1"}, expected: "HSET key1 \"key value 1\""}, }