Yangsx-1 commented on code in PR #1490:
URL:
https://github.com/apache/incubator-kvrocks/pull/1490#discussion_r1231254977
##########
src/commands/cmd_zset.cc:
##########
@@ -220,64 +222,218 @@ class CommandZLexCount : public Commander {
RangeLexSpec spec_;
};
-class CommandZPop : public Commander {
+class CommandZPop : public Commander,
+ private EvbufCallbackBase<CommandZPop, false>,
+ private EventCallbackBase<CommandZPop> {
public:
- explicit CommandZPop(bool min) : min_(min) {}
+ explicit CommandZPop(bool min, bool block) : min_(min), block_(block) {}
Status Parse(const std::vector<std::string> &args) override {
- if (args.size() > 3) {
- return {Status::RedisParseErr, errWrongNumOfArguments};
- }
+ if (!block_) {
+ if (args.size() > 3) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+
+ if (args.size() == 3) {
+ auto parse_result = ParseInt<int>(args[2], 10);
+ if (!parse_result) {
+ return {Status::RedisParseErr, errValueNotInteger};
+ }
- if (args.size() == 3) {
- auto parse_result = ParseInt<int>(args[2], 10);
- if (!parse_result) {
- return {Status::RedisParseErr, errValueNotInteger};
+ count_ = *parse_result;
}
+ keys_.push_back(args[1]);
+ return Commander::Parse(args);
+ }
+ auto parse_result = ParseInt<int>(args[args.size() - 1], 10);
- count_ = *parse_result;
+ if (!parse_result) {
+ return {Status::RedisParseErr, "timeout is not an integer or out of
range"};
}
+
+ if (*parse_result < 0) {
+ return {Status::RedisParseErr, errTimeoutIsNegative};
+ }
+
+ timeout_ = *parse_result;
+
+ keys_ = std::vector<std::string>(args.begin() + 1, args.end() - 1);
return Commander::Parse(args);
}
Status Execute(Server *svr, Connection *conn, std::string *output) override {
- redis::ZSet zset_db(svr->storage, conn->GetNamespace());
- std::vector<MemberScore> member_scores;
- auto s = zset_db.Pop(args_[1], count_, min_, &member_scores);
+ svr_ = svr;
+ conn_ = conn;
+
+ auto s = TryPopFromMultiZset();
Review Comment:
The function `TryPopFromMultiZset()` is also used in function `OnWrite`
later, i think expanding the code here rather than using a function will cause
duplication.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]