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 <golang@88.com>

* add XInfoStreamFull test

Signed-off-by: monkey92t <golang@88.com>

* add test XInfoStreamFull entries_read = nil

Signed-off-by: monkey92t <golang@88.com>

---------

Signed-off-by: monkey92t <golang@88.com>
This commit is contained in:
Monkey 2023-05-29 13:40:45 +08:00 committed by GitHub
parent 9a9423d3df
commit 6f0af685cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 92 additions and 1 deletions

View File

@ -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":

View File

@ -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() {