From 6f0af685cfb93fd0d70a8f1f3f8b8ceaac11516e Mon Sep 17 00:00:00 2001 From: Monkey Date: Mon, 29 May 2023 13:40:45 +0800 Subject: [PATCH] fix the reading of the "entries-read" field in XInfoStreamFull (#2595) * fix: In the response of the XInfoStreamFull command, the "entries-read" field may be nil Signed-off-by: monkey92t * add XInfoStreamFull test Signed-off-by: monkey92t * add test XInfoStreamFull entries_read = nil Signed-off-by: monkey92t --------- Signed-off-by: monkey92t --- command.go | 2 +- commands_test.go | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index fd07d82a..f10e7365 100644 --- a/command.go +++ b/command.go @@ -2373,7 +2373,7 @@ func readStreamGroups(rd *proto.Reader) ([]XInfoStreamGroup, error) { } case "entries-read": group.EntriesRead, err = rd.ReadInt() - if err != nil { + if err != nil && err != Nil { return nil, err } case "lag": diff --git a/commands_test.go b/commands_test.go index 914a3149..281defbf 100644 --- a/commands_test.go +++ b/commands_test.go @@ -5912,6 +5912,97 @@ var _ = Describe("Commands", func() { } } } + + Expect(res.Groups).To(Equal([]redis.XInfoStreamGroup{ + { + Name: "group1", + LastDeliveredID: "3-0", + EntriesRead: 3, + Lag: 0, + PelCount: 3, + Pending: []redis.XInfoStreamGroupPending{ + {ID: "1-0", Consumer: "consumer1", DeliveryTime: time.Time{}, DeliveryCount: 1}, + {ID: "2-0", Consumer: "consumer1", DeliveryTime: time.Time{}, DeliveryCount: 1}, + }, + Consumers: []redis.XInfoStreamConsumer{ + { + Name: "consumer1", + SeenTime: time.Time{}, + ActiveTime: time.Time{}, + PelCount: 2, + Pending: []redis.XInfoStreamConsumerPending{ + {ID: "1-0", DeliveryTime: time.Time{}, DeliveryCount: 1}, + {ID: "2-0", DeliveryTime: time.Time{}, DeliveryCount: 1}, + }, + }, + { + Name: "consumer2", + SeenTime: time.Time{}, + ActiveTime: time.Time{}, + PelCount: 1, + Pending: []redis.XInfoStreamConsumerPending{ + {ID: "3-0", DeliveryTime: time.Time{}, DeliveryCount: 1}, + }, + }, + }, + }, + { + Name: "group2", + LastDeliveredID: "3-0", + EntriesRead: 3, + Lag: 0, + PelCount: 2, + Pending: []redis.XInfoStreamGroupPending{ + {ID: "2-0", Consumer: "consumer1", DeliveryTime: time.Time{}, DeliveryCount: 1}, + {ID: "3-0", Consumer: "consumer1", DeliveryTime: time.Time{}, DeliveryCount: 1}, + }, + Consumers: []redis.XInfoStreamConsumer{ + { + Name: "consumer1", + SeenTime: time.Time{}, + ActiveTime: time.Time{}, + PelCount: 2, + Pending: []redis.XInfoStreamConsumerPending{ + {ID: "2-0", DeliveryTime: time.Time{}, DeliveryCount: 1}, + {ID: "3-0", DeliveryTime: time.Time{}, DeliveryCount: 1}, + }, + }, + }, + }, + })) + + // entries-read = nil + Expect(client.Del(ctx, "xinfo-stream-full-stream").Err()).NotTo(HaveOccurred()) + id, err := client.XAdd(ctx, &redis.XAddArgs{ + Stream: "xinfo-stream-full-stream", + ID: "*", + Values: []any{"k1", "v1"}, + }).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(client.XGroupCreateMkStream(ctx, "xinfo-stream-full-stream", "xinfo-stream-full-group", "0").Err()).NotTo(HaveOccurred()) + res, err = client.XInfoStreamFull(ctx, "xinfo-stream-full-stream", 0).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(res).To(Equal(&redis.XInfoStreamFull{ + Length: 1, + RadixTreeKeys: 1, + RadixTreeNodes: 2, + LastGeneratedID: id, + MaxDeletedEntryID: "0-0", + EntriesAdded: 1, + Entries: []redis.XMessage{{ID: id, Values: map[string]any{"k1": "v1"}}}, + Groups: []redis.XInfoStreamGroup{ + { + Name: "xinfo-stream-full-group", + LastDeliveredID: "0-0", + EntriesRead: 0, + Lag: 1, + PelCount: 0, + Pending: []redis.XInfoStreamGroupPending{}, + Consumers: []redis.XInfoStreamConsumer{}, + }, + }, + RecordedFirstEntryID: id, + })) }) It("should XINFO GROUPS", func() {