ltagliamonte-dd commented on code in PR #2827:
URL: https://github.com/apache/kvrocks/pull/2827#discussion_r2001685626


##########
src/commands/cmd_key.cc:
##########
@@ -553,6 +553,68 @@ class CommandSort : public Commander {
   SortArgument sort_argument_;
 };
 
+class CommandGetMeta : public Commander {
+ public:
+  Status Parse(const std::vector<std::string> &args) override {
+    if (args.size() != 2) {
+      return {Status::RedisExecErr, errWrongNumOfArguments};
+    }
+    return Status::OK();
+  }
+
+  Status Execute(engine::Context &ctx, Server *srv, Connection *conn, 
std::string *output) override {
+    redis::Database redis(srv->storage, conn->GetNamespace());
+    std::string &key = args_[1];
+    std::string nskey = redis.AppendNamespacePrefix(key);
+
+    RedisType type = kRedisNone;
+    auto s = redis.Type(ctx, key, &type);
+    if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
+    if (type == kRedisNone) {
+      *output = conn->NilString();
+      return Status::OK();
+    }
+
+    // Create appropriate metadata object based on type
+    std::unique_ptr<Metadata> metadata;
+    switch (type) {
+      case kRedisString:
+        metadata = std::make_unique<StringMetadata>();
+        break;
+      case kRedisHash:
+        metadata = std::make_unique<HashMetadata>();
+        break;
+      case kRedisSet:
+        metadata = std::make_unique<SetMetadata>();
+        break;
+      case kRedisZSet:
+        metadata = std::make_unique<ZSetMetadata>();
+        break;
+      case kRedisBitmap:
+        metadata = std::make_unique<BitmapMetadata>();
+        break;
+      case kRedisList:
+        metadata = std::make_unique<ListMetadata>();
+        break;
+      default:
+        return {Status::RedisExecErr, "Unimplemented Redis type"};
+    }
+
+    // Get metadata
+    s = redis.GetMetadata(ctx, {type}, nskey, metadata.get());

Review Comment:
   i'm not following completely this suggestion do you mind giving more details?



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