You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by hu...@apache.org on 2023/04/09 14:17:25 UTC
[incubator-kvrocks] branch unstable updated: Add MEMORY USAGE command as an alias to existing DISK USAGE command (#1375)
This is an automated email from the ASF dual-hosted git repository.
hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new f0897583 Add MEMORY USAGE command as an alias to existing DISK USAGE command (#1375)
f0897583 is described below
commit f0897583dd846e83b41a44fa050b1565080cb579
Author: Yaroslav <to...@gmail.com>
AuthorDate: Sun Apr 9 17:17:19 2023 +0300
Add MEMORY USAGE command as an alias to existing DISK USAGE command (#1375)
---
src/commands/cmd_server.cc | 6 ++++--
tests/gocase/unit/disk/disk_test.go | 12 ++++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/commands/cmd_server.cc b/src/commands/cmd_server.cc
index 6cfa5fa1..3009aef2 100644
--- a/src/commands/cmd_server.cc
+++ b/src/commands/cmd_server.cc
@@ -296,6 +296,8 @@ class CommandDisk : public Commander {
}
};
+class CommandMemory : public CommandDisk {};
+
class CommandRole : public Commander {
public:
Status Execute(Server *svr, Connection *conn, std::string *output) override {
@@ -645,14 +647,13 @@ class CommandHello final : public Commander {
Status Execute(Server *svr, Connection *conn, std::string *output) override {
size_t next_arg = 1;
if (args_.size() >= 2) {
- int64_t protocol = 0;
auto parse_result = ParseInt<int64_t>(args_[next_arg], 10);
++next_arg;
if (!parse_result) {
return {Status::NotOK, "Protocol version is not an integer or out of range"};
}
- protocol = *parse_result;
+ int64_t protocol = *parse_result;
// In redis, it will check protocol < 2 or protocol > 3,
// kvrocks only supports REPL2 by now, but for supporting some
@@ -941,6 +942,7 @@ REDIS_REGISTER_COMMANDS(MakeCmdAttr<CommandAuth>("auth", 2, "read-only ok-loadin
MakeCmdAttr<CommandCommand>("command", -1, "read-only", 0, 0, 0),
MakeCmdAttr<CommandEcho>("echo", 2, "read-only", 0, 0, 0),
MakeCmdAttr<CommandDisk>("disk", 3, "read-only", 0, 0, 0),
+ MakeCmdAttr<CommandMemory>("memory", 3, "read-only", 0, 0, 0),
MakeCmdAttr<CommandHello>("hello", -1, "read-only ok-loading", 0, 0, 0),
MakeCmdAttr<CommandCompact>("compact", 1, "read-only no-script", 0, 0, 0),
diff --git a/tests/gocase/unit/disk/disk_test.go b/tests/gocase/unit/disk/disk_test.go
index c2d86f44..8eccbd61 100644
--- a/tests/gocase/unit/disk/disk_test.go
+++ b/tests/gocase/unit/disk/disk_test.go
@@ -24,6 +24,7 @@ import (
"strconv"
"strings"
"testing"
+ "time"
"github.com/apache/incubator-kvrocks/tests/gocase/util"
"github.com/go-redis/redis/v9"
@@ -142,4 +143,15 @@ func TestDisk(t *testing.T) {
require.ErrorContains(t, rdb.Do(ctx, "Disk", "usage", "nonexistentkey").Err(), "Not found")
})
+ t.Run("Memory usage existing key - check that Kvrocks support it", func(t *testing.T) {
+ key := "arbitrary-key"
+ require.NoError(t, rdb.Del(ctx, key).Err())
+
+ require.NoError(t, rdb.Set(ctx, key, "some-arbitrary-value-with-non-zero-length",
+ time.Duration(0)).Err())
+
+ size, err := rdb.MemoryUsage(ctx, key).Result()
+ require.NoError(t, err)
+ require.Greater(t, size, int64(0))
+ })
}