Skip to content

Commit d7ab0b5

Browse files
authored
fix: XREADGROUP key extraction for STREAMS consumer name (#7721)
1 parent b2ae5f9 commit d7ab0b5

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

src/server/stream_family_test.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,18 @@ TEST_F(StreamFamilyTest, XReadGroup) {
299299
EXPECT_THAT(resp, ArgType(RespExpr::NIL_ARRAY));
300300
}
301301

302+
TEST_F(StreamFamilyTest, XReadGroupConsumerNamedStreams) {
303+
Run({"XADD", "COUNT", "1-0", "field", "value"});
304+
Run({"XGROUP", "CREATE", "COUNT", "grp1", "0"});
305+
Run({"XADD", "2", "1-0", "field", "value"});
306+
Run({"XGROUP", "CREATE", "2", "grp1", "0"});
307+
Run({"XADD", "xp1", "1-0", "field", "value"});
308+
Run({"XGROUP", "CREATE", "xp1", "grp1", "0"});
309+
310+
auto resp = Run({"XREADGROUP", "GROUP", "grp1", "STREAMS", "COUNT", "2", "STREAMS", "xp1", ">"});
311+
EXPECT_THAT(resp, RespElementsAre(RespArray(ElementsAre("xp1", ArrLen(1)))));
312+
}
313+
302314
TEST_F(StreamFamilyTest, XReadBlock) {
303315
Run({"xadd", "foo", "1-*", "k1", "v1"});
304316
Run({"xadd", "foo", "1-*", "k2", "v2"});

src/server/transaction.cc

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,14 +1652,46 @@ OpResult<KeyIndex> DetermineKeys(const CommandId* cid, const facade::ParsedArgs&
16521652

16531653
string_view name{cid->name()};
16541654

1655-
// Determine based on STREAMS argument position
1655+
// Determine based on the STREAMS option position.
16561656
if (name == "XREAD" || name == "XREADGROUP") {
1657-
for (size_t i = 0; i < args.size(); ++i) {
1657+
size_t i = 0;
1658+
if (name == "XREADGROUP") {
1659+
i = 3; // GROUP <group> <consumer>
1660+
}
1661+
1662+
while (i < args.size()) {
16581663
string_view arg = args[i];
16591664
if (absl::EqualsIgnoreCase(arg, "STREAMS")) {
16601665
size_t left = args.size() - i - 1;
16611666
return KeyIndex(i + 1, i + 1 + (left / 2));
16621667
}
1668+
1669+
if (absl::EqualsIgnoreCase(arg, "COUNT")) {
1670+
if (i + 1 >= args.size())
1671+
return OpStatus::SYNTAX_ERR;
1672+
uint32_t count;
1673+
if (!absl::SimpleAtoi(args[i + 1], &count))
1674+
return OpStatus::INVALID_INT;
1675+
i += 2;
1676+
continue;
1677+
}
1678+
1679+
if (absl::EqualsIgnoreCase(arg, "BLOCK")) {
1680+
if (i + 1 >= args.size())
1681+
return OpStatus::SYNTAX_ERR;
1682+
int64_t timeout;
1683+
if (!absl::SimpleAtoi(args[i + 1], &timeout))
1684+
return OpStatus::INVALID_INT;
1685+
i += 2;
1686+
continue;
1687+
}
1688+
1689+
if (name == "XREADGROUP" && absl::EqualsIgnoreCase(arg, "NOACK")) {
1690+
++i;
1691+
continue;
1692+
}
1693+
1694+
break;
16631695
}
16641696
return OpStatus::SYNTAX_ERR;
16651697
}

0 commit comments

Comments
 (0)