Skip to content

Commit 6f0af68

Browse files
authored
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 <[email protected]> * add XInfoStreamFull test Signed-off-by: monkey92t <[email protected]> * add test XInfoStreamFull entries_read = nil Signed-off-by: monkey92t <[email protected]> --------- Signed-off-by: monkey92t <[email protected]>
1 parent 9a9423d commit 6f0af68

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,7 @@ func readStreamGroups(rd *proto.Reader) ([]XInfoStreamGroup, error) {
23732373
}
23742374
case "entries-read":
23752375
group.EntriesRead, err = rd.ReadInt()
2376-
if err != nil {
2376+
if err != nil && err != Nil {
23772377
return nil, err
23782378
}
23792379
case "lag":

commands_test.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5912,6 +5912,97 @@ var _ = Describe("Commands", func() {
59125912
}
59135913
}
59145914
}
5915+
5916+
Expect(res.Groups).To(Equal([]redis.XInfoStreamGroup{
5917+
{
5918+
Name: "group1",
5919+
LastDeliveredID: "3-0",
5920+
EntriesRead: 3,
5921+
Lag: 0,
5922+
PelCount: 3,
5923+
Pending: []redis.XInfoStreamGroupPending{
5924+
{ID: "1-0", Consumer: "consumer1", DeliveryTime: time.Time{}, DeliveryCount: 1},
5925+
{ID: "2-0", Consumer: "consumer1", DeliveryTime: time.Time{}, DeliveryCount: 1},
5926+
},
5927+
Consumers: []redis.XInfoStreamConsumer{
5928+
{
5929+
Name: "consumer1",
5930+
SeenTime: time.Time{},
5931+
ActiveTime: time.Time{},
5932+
PelCount: 2,
5933+
Pending: []redis.XInfoStreamConsumerPending{
5934+
{ID: "1-0", DeliveryTime: time.Time{}, DeliveryCount: 1},
5935+
{ID: "2-0", DeliveryTime: time.Time{}, DeliveryCount: 1},
5936+
},
5937+
},
5938+
{
5939+
Name: "consumer2",
5940+
SeenTime: time.Time{},
5941+
ActiveTime: time.Time{},
5942+
PelCount: 1,
5943+
Pending: []redis.XInfoStreamConsumerPending{
5944+
{ID: "3-0", DeliveryTime: time.Time{}, DeliveryCount: 1},
5945+
},
5946+
},
5947+
},
5948+
},
5949+
{
5950+
Name: "group2",
5951+
LastDeliveredID: "3-0",
5952+
EntriesRead: 3,
5953+
Lag: 0,
5954+
PelCount: 2,
5955+
Pending: []redis.XInfoStreamGroupPending{
5956+
{ID: "2-0", Consumer: "consumer1", DeliveryTime: time.Time{}, DeliveryCount: 1},
5957+
{ID: "3-0", Consumer: "consumer1", DeliveryTime: time.Time{}, DeliveryCount: 1},
5958+
},
5959+
Consumers: []redis.XInfoStreamConsumer{
5960+
{
5961+
Name: "consumer1",
5962+
SeenTime: time.Time{},
5963+
ActiveTime: time.Time{},
5964+
PelCount: 2,
5965+
Pending: []redis.XInfoStreamConsumerPending{
5966+
{ID: "2-0", DeliveryTime: time.Time{}, DeliveryCount: 1},
5967+
{ID: "3-0", DeliveryTime: time.Time{}, DeliveryCount: 1},
5968+
},
5969+
},
5970+
},
5971+
},
5972+
}))
5973+
5974+
// entries-read = nil
5975+
Expect(client.Del(ctx, "xinfo-stream-full-stream").Err()).NotTo(HaveOccurred())
5976+
id, err := client.XAdd(ctx, &redis.XAddArgs{
5977+
Stream: "xinfo-stream-full-stream",
5978+
ID: "*",
5979+
Values: []any{"k1", "v1"},
5980+
}).Result()
5981+
Expect(err).NotTo(HaveOccurred())
5982+
Expect(client.XGroupCreateMkStream(ctx, "xinfo-stream-full-stream", "xinfo-stream-full-group", "0").Err()).NotTo(HaveOccurred())
5983+
res, err = client.XInfoStreamFull(ctx, "xinfo-stream-full-stream", 0).Result()
5984+
Expect(err).NotTo(HaveOccurred())
5985+
Expect(res).To(Equal(&redis.XInfoStreamFull{
5986+
Length: 1,
5987+
RadixTreeKeys: 1,
5988+
RadixTreeNodes: 2,
5989+
LastGeneratedID: id,
5990+
MaxDeletedEntryID: "0-0",
5991+
EntriesAdded: 1,
5992+
Entries: []redis.XMessage{{ID: id, Values: map[string]any{"k1": "v1"}}},
5993+
Groups: []redis.XInfoStreamGroup{
5994+
{
5995+
Name: "xinfo-stream-full-group",
5996+
LastDeliveredID: "0-0",
5997+
EntriesRead: 0,
5998+
Lag: 1,
5999+
PelCount: 0,
6000+
Pending: []redis.XInfoStreamGroupPending{},
6001+
Consumers: []redis.XInfoStreamConsumer{},
6002+
},
6003+
},
6004+
RecordedFirstEntryID: id,
6005+
}))
59156006
})
59166007

59176008
It("should XINFO GROUPS", func() {

0 commit comments

Comments
 (0)