Skip to content

Commit

Permalink
Merge branch 'unstable' into aleksraiden-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
PragmaTwice committed Sep 15, 2024
2 parents eb3f406 + 5110486 commit 9decde2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/storage/rdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
#include "rdb_listpack.h"
#include "rdb_ziplist.h"
#include "rdb_zipmap.h"
#include "storage/redis_metadata.h"
#include "time_util.h"
#include "types/redis_bitmap.h"
#include "types/redis_bitmap_string.h"
#include "types/redis_hash.h"
#include "types/redis_list.h"
#include "types/redis_set.h"
Expand Down Expand Up @@ -718,7 +721,7 @@ Status RDB::Dump(const std::string &key, const RedisType type) {

Status RDB::SaveObjectType(const RedisType type) {
int robj_type = -1;
if (type == kRedisString) {
if (type == kRedisString || type == kRedisBitmap) {
robj_type = RDBTypeString;
} else if (type == kRedisHash) {
robj_type = RDBTypeHash;
Expand Down Expand Up @@ -781,6 +784,16 @@ Status RDB::SaveObject(const std::string &key, const RedisType type) {
}

return SaveHashObject(field_values);
} else if (type == kRedisBitmap) {
std::string value;
redis::Bitmap bitmap_db(storage_, ns_);
Config *config = storage_->GetConfig();
uint32_t max_btos_size = static_cast<uint32_t>(config->max_bitmap_to_string_mb) * MiB;
auto s = bitmap_db.GetString(ctx, key, max_btos_size, &value);
if (!s.ok() && !s.IsNotFound()) {
return {Status::RedisExecErr, s.ToString()};
}
return SaveStringObject(value);
} else {
LOG(WARNING) << "Invalid or Not supported object type: " << type;
return {Status::NotOK, "Invalid or Not supported object type"};
Expand Down
18 changes: 18 additions & 0 deletions tests/gocase/unit/dump/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,21 @@ func TestDump_Set(t *testing.T) {
require.NoError(t, rdb.RestoreReplace(ctx, restoredKey, 0, serialized).Err())
require.ElementsMatch(t, members, rdb.SMembers(ctx, restoredKey).Val())
}

func TestDump_Bitset(t *testing.T) {
srv := util.StartServer(t, map[string]string{})
defer srv.Close()

ctx := context.Background()
rdb := srv.NewClient()
defer func() { require.NoError(t, rdb.Close()) }()

key := "bitsetKey1"
require.NoError(t, rdb.SetBit(ctx, key, 1, 1).Err())
serialized, err := rdb.Dump(ctx, key).Result()
require.NoError(t, err)

restoredKey := fmt.Sprintf("restore_%s", key)
require.NoError(t, rdb.RestoreReplace(ctx, restoredKey, 0, serialized).Err())
require.Equal(t, rdb.Get(ctx, key).Val(), rdb.Get(ctx, restoredKey).Val())
}

0 comments on commit 9decde2

Please sign in to comment.