Skip to content

Commit

Permalink
fix core on r.optimize #83 (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkiller authored Jul 8, 2021
1 parent 2a93d78 commit 4ac5d38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/redis-roaring.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions tests/integration_1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -314,5 +321,6 @@ test_getintarray_setintarray
test_getbitarray_setbitarray
test_min_max
test_diff
test_optimize_nokey
test_del
test_save

0 comments on commit 4ac5d38

Please sign in to comment.