git-hulk commented on code in PR #2238:
URL: https://github.com/apache/kvrocks/pull/2238#discussion_r1562251590
##########
src/commands/cmd_key.cc:
##########
@@ -363,20 +361,80 @@ class CommandRenameNX : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
redis::Database redis(srv->storage, conn->GetNamespace());
- bool ret = true;
- bool key_exist = true;
+ Database::CopyResult res = Database::CopyResult::DONE;
std::string ns_key = redis.AppendNamespacePrefix(args_[1]);
std::string new_ns_key = redis.AppendNamespacePrefix(args_[2]);
- auto s = redis.Move(ns_key, new_ns_key, true, &ret, &key_exist);
+ auto s = redis.Copy(ns_key, new_ns_key, true, true, &res);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
- if (!key_exist) return {Status::RedisExecErr,
rocksdb::Status::InvalidArgument("ERR no such key").ToString()};
- if (ret) {
- *output = redis::Integer(1);
- } else {
- *output = redis::Integer(0);
+ switch (res) {
+ case Database::CopyResult::KEY_NOT_EXIST:
+ return {Status::RedisExecErr, rocksdb::Status::InvalidArgument("ERR no
such key").ToString()};
+ case Database::CopyResult::DONE:
+ *output = redis::Integer(1);
+ break;
+ case Database::CopyResult::KEY_ALREADY_EXIST:
+ *output = redis::Integer(0);
+ break;
+ }
+ return Status::OK();
+ }
+};
+
+class CommandCopy : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ if (args.size() > 6) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+ if (args.size() == 4) {
Review Comment:
From the Redis documentation: https://redis.io/docs/latest/commands/copy/,
it doesn't require the DB to be placed before REPLACE. That said: `COPY k0 k1
REPLACE DB 0` is also good for Redis, you can implement the parameter parser
via `CommandParser`.
--
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]