Skip to content

Commit

Permalink
Handle empty values (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannh authored Dec 27, 2023
1 parent ee0a6d3 commit dadcc59
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/redisdump/redisdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
1 change: 1 addition & 0 deletions pkg/redisdump/redisdump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\""},
}

Expand Down

0 comments on commit dadcc59

Please sign in to comment.