Skip to content

Commit

Permalink
Don't create empty map for nil values
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Feb 2, 2020
1 parent 0fdd200 commit 99cd690
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,18 +999,20 @@ func xMessageSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
return nil, err
}

v, err := rd.ReadArrayReply(stringInterfaceMapParser)
if err != nil && err != proto.Nil {
return nil, err
}
var values map[string]interface{}

if v == nil || err == proto.Nil {
v = make(map[string]interface{})
v, err := rd.ReadArrayReply(stringInterfaceMapParser)
if err != nil {
if err != proto.Nil {
return nil, err
}
} else {
values = v.(map[string]interface{})
}

msgs = append(msgs, XMessage{
ID: id,
Values: v.(map[string]interface{}),
Values: values,
})
return nil, nil
})
Expand Down
2 changes: 1 addition & 1 deletion commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3598,7 +3598,7 @@ var _ = Describe("Commands", func() {
Stream: "stream",
Messages: []redis.XMessage{
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
{ID: "2-0", Values: map[string]interface{}{}},
{ID: "2-0", Values: nil},
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
}},
}))
Expand Down

0 comments on commit 99cd690

Please sign in to comment.