Skip to content

Commit 5723398

Browse files
committed
Add quotes for fields containing spaces in CmdSerializer
1 parent df57c6c commit 5723398

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

redisdump/redisdump.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,18 @@ func RedisCmdSerializer(cmd []string) string {
6969
if len(cmd) == 0 {
7070
return ""
7171
}
72-
res := ""
73-
for i, s := range cmd {
74-
if i>0 {
75-
res += " "
76-
}
77-
if strings.Contains(s, " ") {
78-
res += "\"" + s + "\""
72+
73+
buf := strings.Builder{}
74+
buf.WriteString(fmt.Sprintf("%s", cmd[0]))
75+
for i:=1;i< len(cmd);i++{
76+
if strings.Contains(cmd[i], " ") {
77+
buf.WriteString(fmt.Sprintf(" \"%s\"", cmd[i]))
7978
} else {
80-
res += s
79+
buf.WriteString(fmt.Sprintf(" %s", cmd[i]))
8180
}
8281
}
8382

84-
return res
83+
return buf.String()
8584
}
8685

8786
func dumpKeys(client radix.Client, keys []string, withTTL bool, logger *log.Logger, serializer func([]string) string) error {

redisdump/redisdump_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ func TestRedisCmdSerializer(t *testing.T) {
133133
}
134134

135135
testCases := []testCase{
136+
{command: []string{"HELLO"}, expected: "HELLO"},
137+
{command: []string{"HGETALL", "key"}, expected: "HGETALL key"},
136138
{command: []string{"SET", "key name 1", "key value 1"}, expected: "SET \"key name 1\" \"key value 1\""},
137139
{command: []string{"HSET", "key1", "key value 1"}, expected: "HSET key1 \"key value 1\""},
138140
}

0 commit comments

Comments
 (0)