From 072a6ebdc473772926d549aff2974600dc62ff97 Mon Sep 17 00:00:00 2001 From: arthur Date: Wed, 7 Jul 2021 21:57:24 +0800 Subject: [PATCH 1/5] fix core on r.optimize #83 --- src/redis-roaring.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/redis-roaring.c b/src/redis-roaring.c index 45172a4..964daf7 100644 --- a/src/redis-roaring.c +++ b/src/redis-roaring.c @@ -216,8 +216,11 @@ int ROptimizeBitCommand(RedisModuleCtx* ctx, RedisModuleString** argv, int argc) RedisModule_AutoMemory(ctx); RedisModuleKey* key = RedisModule_OpenKey(ctx, argv[1], REDISMODULE_READ); int type = RedisModule_KeyType(key); - if (type != REDISMODULE_KEYTYPE_EMPTY && RedisModule_ModuleTypeGetType(key) != BitmapType) { - return RedisModule_ReplyWithError(ctx, REDISMODULE_ERRORMSG_WRONGTYPE); + if (type == REDISMODULE_KEYTYPE_EMPTY) { + return RedisModule_ReplyWithError(ctx, "ERR no such key"); + } + if (RedisModule_ModuleTypeGetType(key) != BitmapType) { + return RedisModule_ReplyWithError(ctx, REDISMODULE_ERRORMSG_WRONGTYPE); } Bitmap* bitmap = RedisModule_ModuleTypeGetValue(key); From 584d25607fbaa248d65c2a1f8753d9a255f7dbd8 Mon Sep 17 00:00:00 2001 From: arthur Date: Thu, 8 Jul 2021 23:00:10 +0800 Subject: [PATCH 2/5] add test for #83 --- tests/integration_1.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/integration_1.sh b/tests/integration_1.sh index d4ab9dc..00b7716 100755 --- a/tests/integration_1.sh +++ b/tests/integration_1.sh @@ -286,6 +286,13 @@ function test_diff() [ "$FOUND" == "$EXPECTED" ] } +function test_optimize_nokey() +{ + echo "test_optimize nokey" + FOUND=$(echo "R.OPTIMIZE no-key" | ./deps/redis/src/redis-cli) + EXPECTED="ERR no such key" + [ "$FOUND" == "$EXPECTED" ] +} function test_del() { echo "test_del" @@ -314,5 +321,6 @@ test_getintarray_setintarray test_getbitarray_setbitarray test_min_max test_diff +test_optimize_nokey test_del test_save From 0fd5149b2b0cdfd154aac81ed7bc6ede1978e549 Mon Sep 17 00:00:00 2001 From: arthur Date: Fri, 9 Jul 2021 15:46:23 +0800 Subject: [PATCH 3/5] fixing #85 for missing bits, and add write to optimize --- src/redis-roaring.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/redis-roaring.c b/src/redis-roaring.c index 964daf7..03adedb 100644 --- a/src/redis-roaring.c +++ b/src/redis-roaring.c @@ -28,7 +28,9 @@ int RSetFullCommand(RedisModuleCtx* ctx, RedisModuleString** argv, int argc) { return RedisModule_ReplyWithError(ctx, "key exists"); } - Bitmap* bitmap = bitmap_from_range(0, UINT32_MAX - 1); + Bitmap* bitmap = bitmap_from_range(0, UINT32_MAX); + //NOTE bitmap from range is an right open interval, to set full bit for key, we need do it manually + bitmap_setbit(bitmap, UINT32_MAX, 1); RedisModule_ModuleTypeSetValue(key, BitmapType, bitmap); RedisModule_ReplicateVerbatim(ctx); RedisModule_ReplyWithSimpleString(ctx, "OK"); @@ -214,7 +216,7 @@ int ROptimizeBitCommand(RedisModuleCtx* ctx, RedisModuleString** argv, int argc) return RedisModule_WrongArity(ctx); } RedisModule_AutoMemory(ctx); - RedisModuleKey* key = RedisModule_OpenKey(ctx, argv[1], REDISMODULE_READ); + RedisModuleKey* key = RedisModule_OpenKey(ctx, argv[1], REDISMODULE_READ | REDISMODULE_WRITE); int type = RedisModule_KeyType(key); if (type == REDISMODULE_KEYTYPE_EMPTY) { return RedisModule_ReplyWithError(ctx, "ERR no such key"); From 9ee4f05c0f07509b88fc61bd1874dccddf99d32d Mon Sep 17 00:00:00 2001 From: arthur Date: Fri, 9 Jul 2021 15:51:18 +0800 Subject: [PATCH 4/5] add test --- tests/integration_1.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/integration_1.sh b/tests/integration_1.sh index 00b7716..a262a62 100755 --- a/tests/integration_1.sh +++ b/tests/integration_1.sh @@ -293,6 +293,15 @@ function test_optimize_nokey() EXPECTED="ERR no such key" [ "$FOUND" == "$EXPECTED" ] } +function test_setfull() +{ + echo "test_setfull" + echo "del foo" | ./deps/redis/src/redis-cli + echo "R.SETFULL foo" | ./deps/redis/src/redis-cli + FOUND=$(echo "R.BITCOUNT foo" | ./deps/redis/src/redis-cli) + EXPECTED="4294967296" + [ "$FOUND" == "$EXPECTED" ] +} function test_del() { echo "test_del" @@ -322,5 +331,6 @@ test_getbitarray_setbitarray test_min_max test_diff test_optimize_nokey +test_setfull test_del test_save From 669c2316b1dd4348ca4ff372a83384fccfb9ecb5 Mon Sep 17 00:00:00 2001 From: arthur Date: Tue, 13 Jul 2021 18:10:43 +0800 Subject: [PATCH 5/5] fixing memory leak by r.max and r.min --- src/redis-roaring.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/redis-roaring.c b/src/redis-roaring.c index 03adedb..be6173d 100644 --- a/src/redis-roaring.c +++ b/src/redis-roaring.c @@ -741,6 +741,7 @@ int RMinCommand(RedisModuleCtx* ctx, RedisModuleString** argv, int argc) { return RedisModule_WrongArity(ctx); } + RedisModule_AutoMemory(ctx); RedisModuleKey* key = RedisModule_OpenKey(ctx, argv[1], REDISMODULE_READ); int type = RedisModule_KeyType(key); if (type != REDISMODULE_KEYTYPE_EMPTY && RedisModule_ModuleTypeGetType(key) != BitmapType) { @@ -768,6 +769,7 @@ int RMaxCommand(RedisModuleCtx* ctx, RedisModuleString** argv, int argc) { return RedisModule_WrongArity(ctx); } + RedisModule_AutoMemory(ctx); RedisModuleKey* key = RedisModule_OpenKey(ctx, argv[1], REDISMODULE_READ); int type = RedisModule_KeyType(key); if (type != REDISMODULE_KEYTYPE_EMPTY && RedisModule_ModuleTypeGetType(key) != BitmapType) {