You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by GitBox <gi...@apache.org> on 2022/11/15 13:49:43 UTC

[GitHub] [incubator-kvrocks] tanruixiang commented on a diff in pull request #1120: Support more `HRANGE` options

tanruixiang commented on code in PR #1120:
URL: https://github.com/apache/incubator-kvrocks/pull/1120#discussion_r1022809473


##########
src/commands/redis_cmd.cc:
##########
@@ -1508,25 +1508,60 @@ class CommandHGetAll : public Commander {
 class CommandHRange : public Commander {
  public:
   Status Parse(const std::vector<std::string> &args) override {
-    if (args.size() != 6 && args.size() != 4) {
-      return Status(Status::RedisParseErr, errWrongNumOfArguments);
-    }
-    if (args.size() == 6 && Util::ToLower(args[4]) != "limit") {
-      return Status(Status::RedisInvalidCmd, errInvalidSyntax);
+    CommandParser parser(args, 4);
+    while (parser.Good()) {
+      if (parser.EatEqICaseFlag("BYLEX", by_flag_)) {
+      } else if (parser.EatEqICase("REV")) {
+        reversed_ = true;
+      } else if (parser.EatEqICase("LIMIT")) {
+        offset_ = GET_OR_RET(parser.TakeInt());
+        count_ = GET_OR_RET(parser.TakeInt());
+      } else {
+        return parser.InvalidSyntax();
+      }
     }
-    if (args.size() == 6) {
-      auto parse_result = ParseInt<int64_t>(args_[5], 10);
-      if (!parse_result) return Status(Status::RedisParseErr, errValueNotInteger);
-      limit_ = *parse_result;
+    if (by_flag_ == "BYLEX") {
+      spec_.reversed = reversed_;
+      spec_.count = count_;
+      spec_.offset = offset_;
+      Status s;
+      if (spec_.reversed) {
+        s = Redis::Hash::ParseRangeLexSpec(args[3], args[2], &spec_);
+      } else {
+        s = Redis::Hash::ParseRangeLexSpec(args[2], args[3], &spec_);
+      }
+      if (!s.IsOK()) {
+        return Status(Status::RedisParseErr, s.Msg());
+      }
+    } else {
+      by_flag_ = "BYINDEX";

Review Comment:
   Maybe there is a need for a minimum of k values or something similar?



-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org