Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stream): Fix XPENDING serialization issue #2566

Merged
merged 7 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands/cmd_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ class CommandXPending : public Commander {

static Status SendResults([[maybe_unused]] Connection *conn, std::string *output,
StreamGetPendingEntryResult &results) {
output->append(redis::MultiLen(3 + results.consumer_infos.size()));
output->append(redis::MultiLen(4));
output->append(redis::Integer(results.pending_number));
output->append(redis::BulkString(results.first_entry_id.ToString()));
output->append(redis::BulkString(results.last_entry_id.ToString()));
Expand Down
36 changes: 33 additions & 3 deletions tests/gocase/unit/type/stream/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2056,16 +2056,19 @@ func TestStreamOffset(t *testing.T) {
t.Run("XPending with different kinds of commands", func(t *testing.T) {
streamName := "mystream"
groupName := "mygroup"

require.NoError(t, rdb.Del(ctx, streamName).Err())
r, err := rdb.XAck(ctx, streamName, groupName, "0-0").Result()
require.NoError(t, err)

require.Equal(t, int64(0), r)
require.NoError(t, rdb.XAdd(ctx, &redis.XAddArgs{
Stream: streamName,
ID: "1-0",
Values: []string{"field1", "data1"},
}).Err())
require.NoError(t, rdb.XGroupCreate(ctx, streamName, groupName, "0").Err())

consumerName := "myconsumer"
err = rdb.XReadGroup(ctx, &redis.XReadGroupArgs{
Group: groupName,
Expand All @@ -2083,7 +2086,7 @@ func TestStreamOffset(t *testing.T) {
Count: 1,
Lower: "1-0",
Higher: "1-0",
Consumers: map[string]int64{"myconsumer": 1},
Consumers: map[string]int64{consumerName: 1},
nathanlo-hrt marked this conversation as resolved.
Show resolved Hide resolved
}, r1)

require.NoError(t, rdb.XAdd(ctx, &redis.XAddArgs{
Expand Down Expand Up @@ -2113,7 +2116,7 @@ func TestStreamOffset(t *testing.T) {
Count: 3,
Lower: "1-0",
Higher: "2-2",
Consumers: map[string]int64{"myconsumer": 3},
Consumers: map[string]int64{consumerName: 3},
}, r1)

require.NoError(t, rdb.XAck(ctx, streamName, groupName, "2-0").Err())
Expand All @@ -2125,7 +2128,34 @@ func TestStreamOffset(t *testing.T) {
Count: 2,
Lower: "1-0",
Higher: "2-2",
Consumers: map[string]int64{"myconsumer": 2},
Consumers: map[string]int64{consumerName: 2},
}, r1)

// Add a second consumer and check that XPENDING still works
require.NoError(t, rdb.XAdd(ctx, &redis.XAddArgs{
Stream: streamName,
ID: "3-0",
Values: []string{"field1", "data1"},
}).Err())

consumerName2 := "myconsumer2"
err = rdb.XReadGroup(ctx, &redis.XReadGroupArgs{
Group: groupName,
Consumer: consumerName2,
Streams: []string{streamName, ">"},
Count: 1,
NoAck: false,
}).Err()
require.NoError(t, err)

r1, err1 = rdb.XPending(ctx, streamName, groupName).Result()
require.NoError(t, err1)

require.Equal(t, &redis.XPending{
Count: 3,
Lower: "1-0",
Higher: "3-0",
Consumers: map[string]int64{consumerName: 2, consumerName2: 1},
}, r1)
})
}
Expand Down
Loading