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/09/20 02:23:53 UTC

[GitHub] [incubator-kvrocks] caipengbo commented on a diff in pull request #895: Support hrange command

caipengbo commented on code in PR #895:
URL: https://github.com/apache/incubator-kvrocks/pull/895#discussion_r974826268


##########
src/redis_cmd.cc:
##########
@@ -1453,6 +1453,45 @@ 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);
+    }
+    if (args.size() == 6) {
+      auto parseResult = ParseInt<int>(args_[5], /* base= */ 10);
+      if (!parseResult.IsOK())return Status(Status::RedisParseErr, errValueNotInterger);
+      limit_ = parseResult.GetValue();
+    }
+    return Commander::Parse(args);
+  }
+  Status Execute(Server *svr, Connection *conn, std::string *output) override {
+    if (args_.size() == 6 && limit_ < 0) {
+      *output = "*" + std::to_string(0) + CRLF;
+      return Status::OK();
+    }
+    Redis::Hash hash_db(svr->storage_, conn->GetNamespace());
+    std::vector<FieldValue> field_values;
+    rocksdb::Status s = hash_db.Range(args_[1], args_[2], args_[3], limit_, &field_values);
+    if (!s.ok()) {
+      return Status(Status::RedisExecErr, s.ToString());
+    }
+    *output = "*" + std::to_string(field_values.size() * 2) + CRLF;
+    for (const auto &fv : field_values) {
+      *output += Redis::BulkString(fv.field);
+      *output += Redis::BulkString(fv.value);
+    }
+    return Status::OK();

Review Comment:
   Can we use `Redis::MultiBulkString`?



##########
src/redis_cmd.cc:
##########
@@ -1453,6 +1453,45 @@ 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);
+    }
+    if (args.size() == 6) {
+      auto parseResult = ParseInt<int>(args_[5], /* base= */ 10);
+      if (!parseResult.IsOK())return Status(Status::RedisParseErr, errValueNotInterger);
+      limit_ = parseResult.GetValue();
+    }
+    return Commander::Parse(args);
+  }
+  Status Execute(Server *svr, Connection *conn, std::string *output) override {
+    if (args_.size() == 6 && limit_ < 0) {
+      *output = "*" + std::to_string(0) + CRLF;
+      return Status::OK();
+    }

Review Comment:
   This part of the logic, I think we should put it into the `Hash::Range`



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