-
Notifications
You must be signed in to change notification settings - Fork 473
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): add KeyRangeGen
for XRead
and XReadGroup
#2657
fix(stream): add KeyRangeGen
for XRead
and XReadGroup
#2657
Conversation
src/commands/cmd_stream.cc
Outdated
@@ -1715,6 +1684,27 @@ class CommandXReadGroup : public Commander, | |||
bufferevent_enable(bev, EV_READ); | |||
} | |||
|
|||
static CommandKeyRangeGen KeyRangeGen() { | |||
static constexpr auto keyRangeGenFunc = [](const std::vector<std::string> &args) { | |||
auto parsed_args = *parse(args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm actually from my side I don't think we need to reuse the code of Parse()
, since:
- many fields in
parsed_args
is useless in key range gen, so we made lots of useless string copies. - in key range gen we can assume that the syntax of the input args is valid, so we can omit many checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @PragmaTwice ,
Thanks for your suggestions! 😊
I have reverted the original Parse
function and add a simple search function for parsing stream key counts.
Best Regards,
Edward
src/commands/cmd_stream.cc
Outdated
static CommandKeyRangeGen KeyRangeGen() { | ||
static constexpr auto keyRangeGenFunc = [](const std::vector<std::string> &args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static CommandKeyRangeGen KeyRangeGen() { | |
static constexpr auto keyRangeGenFunc = [](const std::vector<std::string> &args) { | |
static CommandKeyRange KeyRangeGen(const std::vector<std::string> &args) { |
Also we don't need to make a function that returns a function here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/commands/cmd_stream.cc
Outdated
auto stream_keyword_iter = | ||
std::find_if(args.cbegin(), args.cend(), [](const std::string &arg) { return util::ToLower(arg) == "streams"; }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto stream_keyword_iter = | |
std::find_if(args.cbegin(), args.cend(), [](const std::string &arg) { return util::ToLower(arg) == "streams"; }); | |
auto stream_keyword_iter = | |
std::find_if(args.cbegin(), args.cend(), [](const std::string &arg) { return util::EqualICase(arg, "streams"); }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @PragmaTwice ,
Thanks very much for your suggestion! 😊
I have replaced the comparison operator to util::EqualICase
.
Best Regards,
Edward
src/commands/cmd_stream.cc
Outdated
auto stream_keyword_iter = | ||
std::find_if(args.cbegin(), args.cend(), [](const std::string &arg) { return util::EqualICase(arg, "streams"); }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For XREADGROUP, I think we need to find from begin + 4
, to avoid a group or consumer named streams
.
refer to https://redis.io/docs/latest/commands/xreadgroup/ .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @PragmaTwice ,
Thanks very much for your review! 😊
I have updated the ParseStreamReadRange
with a begin offset.
Best Regards,
Edward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good to me.
Would you like to write a go test case that calls redis command COMMAND GETKEYS XREAD/XREADGROUP ...
to confirm the returned keys is correct?
You can add a new test like https://github.com/apache/kvrocks/blob/unstable/tests/gocase/unit/command/command_test.go#L125.
Of course! I will add unittest later today.😄 Best Regards, |
Hi @PragmaTwice , I have added related unit tests for different combinations of Best Regards, |
Quality Gate failedFailed conditions |
Issue
Close #2625 .
Proposed Changes
Parse
function forXRead
andXReadGroup
.KeyRangeGen
forXRead
andXReadGroup
.