Skip to content

Commit dadcc59

Browse files
authored
Handle empty values (#49)
1 parent ee0a6d3 commit dadcc59

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

pkg/redisdump/redisdump.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func RedisCmdSerializer(cmd []string) string {
127127
buf := strings.Builder{}
128128
buf.WriteString(fmt.Sprintf("%s", cmd[0]))
129129
for i := 1; i < len(cmd); i++ {
130-
if strings.Contains(cmd[i], " ") {
130+
if strings.Contains(cmd[i], " ") || len(cmd[i]) == 0 {
131131
buf.WriteString(fmt.Sprintf(" \"%s\"", cmd[i]))
132132
} else {
133133
buf.WriteString(fmt.Sprintf(" %s", cmd[i]))

pkg/redisdump/redisdump_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ func TestRedisCmdSerializer(t *testing.T) {
214214
{command: []string{"HELLO"}, expected: "HELLO"},
215215
{command: []string{"HGETALL", "key"}, expected: "HGETALL key"},
216216
{command: []string{"SET", "key name 1", "key value 1"}, expected: "SET \"key name 1\" \"key value 1\""},
217+
{command: []string{"SET", "key", ""}, expected: "SET key \"\""},
217218
{command: []string{"HSET", "key1", "key value 1"}, expected: "HSET key1 \"key value 1\""},
218219
}
219220

0 commit comments

Comments
 (0)