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:54:28 UTC

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

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


##########
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:
   @tanruixiang What do you mean by "the smallest element in a hash"?



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