Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MEMORY USAGE command as an alias to existing DISK USAGE command #1375

Merged
merged 1 commit into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/commands/cmd_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
12 changes: 12 additions & 0 deletions tests/gocase/unit/disk/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strconv"
"strings"
"testing"
"time"

"github.com/apache/incubator-kvrocks/tests/gocase/util"
"github.com/go-redis/redis/v9"
Expand Down Expand Up @@ -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))
})
}