Skip to content

Commit

Permalink
Fix TYPE command with bloom filter (#1747)
Browse files Browse the repository at this point in the history
When #1699 introduced BloomFilter, RedisTypeNames was not modified
at the same time, causing the TYPE command return nothing in bf key.
Now it will return `MBbloom--` (keep names consistent with Redis).

Signed-off-by: Jinze Wu <294843472@qq.com>
  • Loading branch information
gogim1 authored Sep 9, 2023
1 parent 1e9a609 commit 166f9a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/commands/cmd_key.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class CommandType : public Commander {
RedisType type = kRedisNone;
auto s = redis.Type(args_[1], &type);
if (s.ok()) {
if (type >= RedisTypeNames.size()) return {Status::RedisExecErr, "Invalid type"};
*output = redis::SimpleString(RedisTypeNames[type]);
return Status::OK();
}
Expand Down
6 changes: 4 additions & 2 deletions src/storage/redis_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ constexpr bool USE_64BIT_COMMON_FIELD_DEFAULT = METADATA_ENCODING_VERSION != 0;

// We write enum integer value of every datatype
// explicitly since it cannot be changed once confirmed
// Note that if you want to add a new redis type in `RedisType`
// you should also add a type name to the `RedisTypeNames` below
enum RedisType {
kRedisNone = 0,
kRedisString = 1,
Expand Down Expand Up @@ -61,8 +63,8 @@ enum RedisCommand {
kRedisCmdLMove,
};

const std::vector<std::string> RedisTypeNames = {"none", "string", "hash", "list", "set",
"zset", "bitmap", "sortedint", "stream"};
const std::vector<std::string> RedisTypeNames = {"none", "string", "hash", "list", "set",
"zset", "bitmap", "sortedint", "stream", "MBbloom--"};

constexpr const char *kErrMsgWrongType = "WRONGTYPE Operation against a key holding the wrong kind of value";
constexpr const char *kErrMsgKeyExpired = "the key was expired";
Expand Down
6 changes: 6 additions & 0 deletions tests/gocase/unit/type/bloom/bloom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,11 @@ func TestBloom(t *testing.T) {
require.Equal(t, int64(1), rdb.Do(ctx, "bf.info", key, "items").Val())
})

t.Run("Get type of bloom filter", func(t *testing.T) {
require.NoError(t, rdb.Del(ctx, key).Err())
require.NoError(t, rdb.Do(ctx, "bf.reserve", key, "0.02", "1000").Err())
require.Equal(t, "MBbloom--", rdb.Type(ctx, key).Val())
})

// TODO: Add the testcase of get filters of bloom filter after complete the scaling.
}

0 comments on commit 166f9a7

Please sign in to comment.