fix: remove xread required arguments (#1263)

This commit is contained in:
Andy Dunstall 2023-05-22 20:29:41 +01:00 committed by GitHub
parent cbb2afc792
commit 832b1c9b64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 30 deletions

View file

@ -1197,7 +1197,6 @@ void StreamFamily::XRead(CmdArgList args, ConnectionContext* cntx) {
size_t streams_arg = 0;
uint32_t count = kuint32max;
bool count_found = false;
// Parse the arguments.
for (size_t id_indx = 0; id_indx < args.size(); ++id_indx) {
@ -1213,7 +1212,6 @@ void StreamFamily::XRead(CmdArgList args, ConnectionContext* cntx) {
if (!absl::SimpleAtoi(arg, &count)) {
return (*cntx)->SendError(kSyntaxErr);
}
count_found = true;
} else if (arg == "STREAMS" && remaining_args > 0) {
streams_arg = id_indx + 1;
@ -1235,15 +1233,6 @@ void StreamFamily::XRead(CmdArgList args, ConnectionContext* cntx) {
return (*cntx)->SendError(kSyntaxErr);
}
// TODO NB: Currently require 2 streams and a COUNT option due to the
// transaction expecting stream keys at positions 4 and 5.
if (!count_found) {
return (*cntx)->SendError("requires COUNT option", kSyntaxErr);
}
if (streams_count != 2) {
return (*cntx)->SendError("requires 2 streams", kSyntaxErr);
}
ReadOpts read_opts;
read_opts.count = count;
@ -1439,13 +1428,7 @@ void StreamFamily::Register(CommandRegistry* registry) {
<< CI{"XLEN", CO::READONLY | CO::FAST, 2, 1, 1, 1}.HFUNC(XLen)
<< CI{"XRANGE", CO::READONLY, -4, 1, 1, 1}.HFUNC(XRange)
<< CI{"XREVRANGE", CO::READONLY, -4, 1, 1, 1}.HFUNC(XRevRange)
// TODO NB: Assuming:
// * We always have a COUNT parameter
// * We always have two streams
// * Don't support BLOCK
// Therefore the command has format:
// XREAD COUNT <count> STREAMS <stream1> <stream2> <id1> <id2>
// Where the keys are <stream1> and <stream2>.
// TODO NB: Doesn't support BLOCK
<< CI{"XREAD", CO::READONLY | CO::REVERSE_MAPPING | CO::VARIADIC_KEYS, -3, 3, 3, 1}
.HFUNC(XRead)
<< CI{"XSETID", CO::WRITE | CO::DENYOOM, 3, 1, 1, 1}.HFUNC(XSetId)

View file

@ -175,18 +175,6 @@ TEST_F(StreamFamilyTest, XReadInvalidArgs) {
// Unbalanced list of streams.
resp = Run({"xread", "count", "invalid", "streams", "s1", "s2", "s3", "0", "0"});
EXPECT_THAT(resp, ErrArg("syntax error"));
// Missing COUNT option.
// TODO Remove once support optional COUNT option.
resp = Run({"xread", "streams", "s1", "s2", "0", "0"});
EXPECT_THAT(resp, ErrArg("requires COUNT option"));
// Less/more than two streams.
// TODO Remove once support a variable number of streams.
resp = Run({"xread", "count", "5", "streams", "s1", "0"});
EXPECT_THAT(resp, ErrArg("requires 2 streams"));
resp = Run({"xread", "count", "5", "streams", "s1", "s2", "s3", "0", "0", "0"});
EXPECT_THAT(resp, ErrArg("requires 2 streams"));
}
TEST_F(StreamFamilyTest, Issue854) {