From 1393126c293906d4c72c5ab95caf0448b403197d Mon Sep 17 00:00:00 2001 From: monkey92t Date: Wed, 19 May 2021 16:52:13 +0800 Subject: [PATCH] fix #1758 (#1759) fix #1758 --- command.go | 8 +++++++- commands_test.go | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index 2edba95..9a3018d 100644 --- a/command.go +++ b/command.go @@ -1769,8 +1769,14 @@ func xStreamInfoParser(rd *proto.Reader, n int64) (interface{}, error) { info.LastGeneratedID, err = rd.ReadString() case "first-entry": info.FirstEntry, err = readXMessage(rd) + if err == Nil { + err = nil + } case "last-entry": info.LastEntry, err = readXMessage(rd) + if err == Nil { + err = nil + } default: return nil, fmt.Errorf("redis: unexpected content %s "+ "in XINFO STREAM reply", key) @@ -2034,7 +2040,7 @@ func readXInfoStreamConsumers(rd *proto.Reader) ([]XInfoStreamConsumer, error) { c.Pending = make([]XInfoStreamConsumerPending, 0, pendingNumber) - for f := 0; f < pendingNumber; f++ { + for pn := 0; pn < pendingNumber; pn++ { nn, err := rd.ReadArrayLen() if err != nil { return nil, err diff --git a/commands_test.go b/commands_test.go index 2d89017..3ae3007 100644 --- a/commands_test.go +++ b/commands_test.go @@ -4390,6 +4390,26 @@ var _ = Describe("Commands", func() { FirstEntry: redis.XMessage{ID: "1-0", Values: map[string]interface{}{"uno": "un"}}, LastEntry: redis.XMessage{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}}, })) + + // stream is empty + n, err := client.XDel(ctx, "stream", "1-0", "2-0", "3-0").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(n).To(Equal(int64(3))) + + res, err = client.XInfoStream(ctx, "stream").Result() + Expect(err).NotTo(HaveOccurred()) + res.RadixTreeKeys = 0 + res.RadixTreeNodes = 0 + + Expect(res).To(Equal(&redis.XInfoStream{ + Length: 0, + RadixTreeKeys: 0, + RadixTreeNodes: 0, + Groups: 2, + LastGeneratedID: "3-0", + FirstEntry: redis.XMessage{}, + LastEntry: redis.XMessage{}, + })) }) It("should XINFO STREAM FULL", func() {