This is an automated email from the ASF dual-hosted git repository.
binbin pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new ba6731fa Add MOVE command as Redis (#1723)
ba6731fa is described below
commit ba6731fa859f959d78f352852da770bea85596a1
Author: Binbin <[email protected]>
AuthorDate: Sat Sep 2 13:48:34 2023 +0800
Add MOVE command as Redis (#1723)
Since kvrocks don't support Redis DBs, so this is a dummy command.
If key does not exist, the command returns 0, otherwise it will always
returns 1.
---
src/commands/cmd_key.cc | 19 +++++++++++++++++++
tests/gocase/unit/introspection/introspection_test.go | 12 ++++++++++++
2 files changed, 31 insertions(+)
diff --git a/src/commands/cmd_key.cc b/src/commands/cmd_key.cc
index 703a0cdf..efcf69f4 100644
--- a/src/commands/cmd_key.cc
+++ b/src/commands/cmd_key.cc
@@ -45,6 +45,24 @@ class CommandType : public Commander {
}
};
+class CommandMove : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ GET_OR_RET(ParseInt<int64_t>(args[2], 10));
+ return Status::OK();
+ }
+
+ Status Execute(Server *svr, Connection *conn, std::string *output) override {
+ int count = 0;
+ redis::Database redis(svr->storage, conn->GetNamespace());
+ rocksdb::Status s = redis.Exists({args_[1]}, &count);
+ if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
+
+ *output = count ? redis::Integer(1) : redis::Integer(0);
+ return Status::OK();
+ }
+};
+
class CommandObject : public Commander {
public:
Status Execute(Server *svr, Connection *conn, std::string *output) override {
@@ -250,6 +268,7 @@ class CommandDel : public Commander {
REDIS_REGISTER_COMMANDS(MakeCmdAttr<CommandTTL>("ttl", 2, "read-only", 1, 1,
1),
MakeCmdAttr<CommandPTTL>("pttl", 2, "read-only", 1, 1,
1),
MakeCmdAttr<CommandType>("type", 2, "read-only", 1, 1,
1),
+ MakeCmdAttr<CommandMove>("move", 3, "write", 1, 1, 1),
MakeCmdAttr<CommandObject>("object", 3, "read-only",
2, 2, 1),
MakeCmdAttr<CommandExists>("exists", -2, "read-only",
1, -1, 1),
MakeCmdAttr<CommandPersist>("persist", 2, "write", 1,
1, 1),
diff --git a/tests/gocase/unit/introspection/introspection_test.go
b/tests/gocase/unit/introspection/introspection_test.go
index 3248b40d..74bf66b8 100644
--- a/tests/gocase/unit/introspection/introspection_test.go
+++ b/tests/gocase/unit/introspection/introspection_test.go
@@ -203,6 +203,18 @@ func TestIntrospection(t *testing.T) {
require.NoError(t, rdb.Set(ctx, "a", "b", 0).Err())
require.GreaterOrEqual(t, time.Since(now).Seconds(), 2.0)
})
+
+ t.Run("MOVE dummy coverage", func(t *testing.T) {
+ require.Error(t, rdb.Do(ctx, "MOVE", "key", "dbid").Err())
+
+ // key does not exist, return 0
+ require.NoError(t, rdb.Do(ctx, "DEL", "key").Err())
+ require.EqualValues(t, 0, rdb.Do(ctx, "MOVE", "key", "0").Val())
+
+ // key exist, always return 1
+ require.NoError(t, rdb.Do(ctx, "SET", "key", "value").Err())
+ require.EqualValues(t, 1, rdb.Do(ctx, "MOVE", "key", "0").Val())
+ })
}
func TestMultiServerIntrospection(t *testing.T) {