uds5501 commented on code in PR #1502:
URL: 
https://github.com/apache/incubator-kvrocks/pull/1502#discussion_r1235515491


##########
src/commands/cmd_zset.cc:
##########
@@ -819,6 +819,81 @@ class CommandZMScore : public Commander {
   }
 };
 
+class CommandZUnion : public Commander {
+ public:
+  Status Parse(const std::vector<std::string> &args) override {
+    auto parse_result = ParseInt<int>(args[1], 10);
+    if (!parse_result) {
+      return {Status::RedisParseErr, errValueNotInteger};
+    }
+
+    numkeys_ = *parse_result;
+    if (numkeys_ > args.size() - 2) {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    size_t key_iterator = 0;
+    while (key_iterator < numkeys_) {
+      keys_weights_.emplace_back(KeyWeight{args[key_iterator + 2], 1});
+      key_iterator++;
+    }
+
+    size_t option_iterator = 2 + numkeys_;
+    while (option_iterator < args.size()) {
+      if (util::ToLower(args[option_iterator]) == "aggregate" && 
option_iterator + 1 < args.size()) {
+        if (util::ToLower(args[option_iterator + 1]) == "sum") {
+          aggregate_method_ = kAggregateSum;
+        } else if (util::ToLower(args[option_iterator + 1]) == "min") {
+          aggregate_method_ = kAggregateMin;
+        } else if (util::ToLower(args[option_iterator + 1]) == "max") {
+          aggregate_method_ = kAggregateMax;
+        } else {
+          return {Status::RedisParseErr, "aggregate param error"};
+        }
+        option_iterator += 2;
+      } else if (util::ToLower(args[option_iterator]) == "weights" && 
option_iterator + numkeys_ < args.size()) {
+        size_t k = 0;
+        while (k < numkeys_) {
+          auto weight = ParseFloat(args[option_iterator + k + 1]);
+          if (!weight || std::isnan(*weight)) {
+            return {Status::RedisParseErr, "weight is not a double or out of 
range"};
+          }
+          keys_weights_[k].weight = *weight;
+          k++;
+        }
+        option_iterator += numkeys_ + 1;
+      } else if (util::ToLower(args[option_iterator]) == "withscores") {
+        with_scores_ = true;

Review Comment:
   Incorporated this change, thanks



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