Update command.go

This commit is contained in:
hible 2023-05-05 20:40:51 +08:00
parent fcb3506e79
commit d5358ff27d
2 changed files with 9 additions and 5 deletions

View File

@ -1452,12 +1452,16 @@ func readXMessageSlice(rd *proto.Reader) ([]XMessage, error) {
return nil, err
}
msgs := make([]XMessage, n)
for i := 0; i < len(msgs); i++ {
if msgs[i], err = readXMessage(rd); err != nil {
return nil, err
msgs := make([]XMessage, 0, n)
for i := 0; i < n; i++ {
if xMessage, err := readXMessage(rd); err == nil {
msgs = append(msgs, xMessage)
}
}
if len(msgs) < 1 {
// Compatible with previous returns
return nil, proto.Nil
}
return msgs, nil
}

View File

@ -5691,7 +5691,7 @@ var _ = Describe("Commands", func() {
Stream: "stream",
Group: "group",
Consumer: "consumer",
Messages: []string{"1-0", "2-0", "3-0"},
Messages: []string{"???-???", "1-0", "2-0", "3-0"},
}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(msgs).To(Equal([]redis.XMessage{{