PragmaTwice commented on code in PR #1490:
URL: 
https://github.com/apache/incubator-kvrocks/pull/1490#discussion_r1232074452


##########
src/commands/cmd_zset.cc:
##########
@@ -221,64 +223,217 @@ 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);

Review Comment:
   For example, in the `Parse` function you write, it is just two code block 
separated by `if (block_)`, i.e.
   ```
   // the original code
   ZPOP::Parse() {
     parse ZPOP...
   }
   
   BZPOP::Parse() {
     parse BZPOP...
   }
   
   // your improved code
   Parse() {
     if(!block_) { 
       parse ZPOP ... 
     } 
     parse BZPOP ... 
   }
   ``` 
   
   IMHO it is not related to deduplication, i.e. the duplicated code seems not 
eliminated at all. 
   And the readabilitiy of the code get even worse in my view.
   



-- 
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]

Reply via email to