Skip to content

Commit

Permalink
Merge branch 'unstable' into fix_mpop_dup_args
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hulk authored Jul 5, 2023
2 parents db436db + fbdc8ad commit bbb6617
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/commands/cmd_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,14 @@ class CommandDisk : public Commander {

uint64_t result = 0;
s = disk_db.GetKeySize(args_[2], type, &result);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
if (!s.ok()) {
// Redis returns the Nil string when the key does not exist
if (s.IsNotFound()) {
*output = redis::NilString();
return Status::OK();
}
return {Status::RedisExecErr, s.ToString()};
}

*output = redis::Integer(result);
return Status::OK();
Expand Down
7 changes: 5 additions & 2 deletions tests/gocase/unit/disk/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ func TestDisk(t *testing.T) {
})

t.Run("Disk usage nonexistent key ", func(t *testing.T) {
require.ErrorContains(t, rdb.Do(ctx, "Disk", "usage", "nonexistentkey").Err(), "Not found")
require.ErrorIs(t, rdb.Do(ctx, "Disk", "usage", "nonexistentkey").Err(), redis.Nil)
})

t.Run("Memory usage existing key - check that Kvrocks support it", func(t *testing.T) {
t.Run("Memory usage - check that Kvrocks support it", func(t *testing.T) {
key := "arbitrary-key"
require.NoError(t, rdb.Del(ctx, key).Err())

Expand All @@ -153,5 +153,8 @@ func TestDisk(t *testing.T) {
size, err := rdb.MemoryUsage(ctx, key).Result()
require.NoError(t, err)
require.Greater(t, size, int64(0))

_, err = rdb.MemoryUsage(ctx, "nonexistentkey").Result()
require.ErrorIs(t, err, redis.Nil)
})
}

0 comments on commit bbb6617

Please sign in to comment.