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/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 51104869 feat: add support of Bitmap type DUMP/RESTORE command support 
(#2535)
51104869 is described below

commit 51104869a19daa086b34881a7f7eb94e7e9ae5b2
Author: lappely | Kirill Gnapovsky <[email protected]>
AuthorDate: Sat Sep 14 19:14:40 2024 +0300

    feat: add support of Bitmap type DUMP/RESTORE command support (#2535)
---
 src/storage/rdb.cc                  | 15 ++++++++++++++-
 tests/gocase/unit/dump/dump_test.go | 18 ++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/storage/rdb.cc b/src/storage/rdb.cc
index 43bad3a0..544e679f 100644
--- a/src/storage/rdb.cc
+++ b/src/storage/rdb.cc
@@ -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"
@@ -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;
@@ -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"};
diff --git a/tests/gocase/unit/dump/dump_test.go 
b/tests/gocase/unit/dump/dump_test.go
index bca9300d..154891c3 100644
--- a/tests/gocase/unit/dump/dump_test.go
+++ b/tests/gocase/unit/dump/dump_test.go
@@ -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())
+}

Reply via email to