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
Support MINID, NOMKSTREAM and LIMIT options for XADD command #1201
Conversation
9892972
to
3006b39
Compare
Hey @romange @dranikpg @royjacobson , could you please rerun the tests and review the PR? |
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.
Great work! Happy to see we're getting support for more and more stream arguments. I've re-run the tests - all passed. Seemed like some internal issue within Github.
src/server/stream_family.cc
Outdated
constexpr uint8_t kAddOptsTrimNone = 0; | ||
constexpr uint8_t kAddOptsTrimMaxLen = 1; | ||
constexpr uint8_t kAddOptsTrimMinId = 2; |
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.
- This can maybe be an enum inside AddOpts
- Instead of using pure numbers we can include the TRIM_STRATEGY defines from redis (move to header before)
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.
Yeah, Sure! I think point number 2 is better
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.
Those are not exclusive 🙂
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.
Could not we completely remove these const expressions and directly use the redis library's TRIM_STRATEGY definitions?
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.
I.e. Something like if (add_opts.trim_strategy == TRIM_STRATEGY_MAXLEN && ...
?
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.
I think yes. enum TrimStrategy {MAX_LEN = TRIM_STRATEGY_MAXLEN, ... = ....}
would be the cleanest, but that'll work too. Just that we don't have hard-coded integers
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.
Ok, I am going with your suggestion then :)
src/server/stream_family_test.cc
Outdated
for (int i = 0; i < 3; i++) { | ||
Run({"xadd", "key3", "*", "field", "val"}); | ||
} | ||
resp = Run({"xadd", "key3", "maxlen", "~", "0", "limit", "1", "*", "field", "val"}); | ||
EXPECT_THAT(Run({"xlen", "key3"}), IntArg(4)); |
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.
Can you please make the limit test a little bit more sophisticated?
Another way to control the amount of work done by the command when using the ~, is the LIMIT clause. When used, it specifies the maximal count of entries that will be evicted
So what should limit 1
do here? It might have no effect because ~
is approximate
although after trimming, the stream may have few tens of additional entries over the threshold.
I'd suggest filling the stream with a few hundreds of entries and then setting a low target for maxlen, so that at least a few dozens will be evicted for sure - and test it. Then do the same, but now call the final xadd with limit and assert that only a few were removed
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.
I was unsure about the test case of limit. So I used one of the redis's "limit" test case. I think your suggestion is great.
Adding these test cases! Thanks.
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.
Great work! Happy to see we're getting support for more and more stream arguments
Pre-commit configuration file can't have two "exclude" key to exclude multiple directories. As a result, pre-commit hook is modifying the src/redis/.* contents. Exclude multiple directories from pre-commit hook correctly. Signed-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
3006b39
to
3f5eb66
Compare
Oops, seems like I forgot to add the |
Redis xadd command have nomkstream, minid and limit options to control the behaviour of xadd command. However dragonfly xadd command doesn't have support for these options. Support NOMKSTREAM, MINID and LIMIT options for XADD command. Signed-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
3f5eb66
to
90c2d4b
Compare
Hi @Abhra303! I noticed that this PR causes some warnings when compiling:
I'm pretty sure this is an actual bug and not a false positive in this case, since some of the uninitialized members are directly used in the follow up. Could you please take a look at the warnings and fix it? Thanks! |
Signed-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
Fixes #1163
XADD command currently doesn't support minid, nomkstream and limit options. This PR aims to support these options.
Additionally, I modified the pre-commit configuration file to correctly exclude multiple files (i.e. src/redis and ci/ directories).