PragmaTwice commented on code in PR #2827:
URL: https://github.com/apache/kvrocks/pull/2827#discussion_r2005279701
##########
src/commands/cmd_key.cc:
##########
@@ -553,6 +553,26 @@ class CommandSort : public Commander {
SortArgument sort_argument_;
};
+class CommandKMetadata : public Commander {
+ public:
+ 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);
+
+ Metadata metadata(kRedisNone, false);
+ auto s = redis.GetMetadata(ctx, RedisTypes::All(), nskey, &metadata);
+ if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
+
+ *output = conn->Map({{redis::BulkString("type"),
redis::BulkString(RedisTypeNames[metadata.Type()])},
+ {redis::BulkString("size"),
redis::Integer(metadata.size)},
+ {redis::BulkString("ttl"),
redis::Integer(metadata.expire)},
+ {redis::BulkString("flags"),
redis::Integer(metadata.flags)},
+ {redis::BulkString("version"),
redis::Integer(metadata.version)}});
Review Comment:
I think we should not give users useless information, even if it can be
easier to decode. IMHO you can set a default value and use the default value if
the field is missing in your application.
--
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]