ltagliamonte-dd commented on code in PR #2827: URL: https://github.com/apache/kvrocks/pull/2827#discussion_r2001187904
########## 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: for my current use case I'm working with redis hashes. I added this other cases to make the cmd support future use cases that someone else (or myself) may have to work on. is it a blocker to leave this is? -- 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-unsubscr...@kvrocks.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org