From 99cd690a7019656b0b67c6664453f27a6d8a658e Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sun, 2 Feb 2020 10:52:57 +0200 Subject: [PATCH] Don't create empty map for nil values --- command.go | 16 +++++++++------- commands_test.go | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/command.go b/command.go index d7c8e0d..c70973d 100644 --- a/command.go +++ b/command.go @@ -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 }) diff --git a/commands_test.go b/commands_test.go index 3970808..392fc09 100644 --- a/commands_test.go +++ b/commands_test.go @@ -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"}}, }}, }))