Skip to content

Commit

Permalink
fix the reading of the "entries-read" field in XInfoStreamFull (#2595)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
monkey92t authored May 29, 2023
1 parent 9a9423d commit 6f0af68
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
91 changes: 91 additions & 0 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 6f0af68

Please sign in to comment.