Test: RM_Call from within "expired" notification (#10613)

This case is interesting because it originates from cron,
rather than from another command.

The idea came from looking at #9890 and #10573, and I was wondering if RM_Call
would work properly when `server.current_client == NULL`
This commit is contained in:
guybe7 2022-04-25 12:05:06 +02:00 committed by GitHub
parent bd823c7fa3
commit 21e39ec461
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 0 deletions

View File

@ -79,6 +79,17 @@ static int KeySpace_NotificationGeneric(RedisModuleCtx *ctx, int type, const cha
return REDISMODULE_OK;
}
static int KeySpace_NotificationExpired(RedisModuleCtx *ctx, int type, const char *event, RedisModuleString *key) {
REDISMODULE_NOT_USED(type);
REDISMODULE_NOT_USED(event);
REDISMODULE_NOT_USED(key);
RedisModuleCallReply* rep = RedisModule_Call(ctx, "INCR", "c!", "testkeyspace:expired");
RedisModule_FreeCallReply(rep);
return REDISMODULE_OK;
}
static int KeySpace_NotificationModule(RedisModuleCtx *ctx, int type, const char *event, RedisModuleString *key) {
REDISMODULE_NOT_USED(ctx);
REDISMODULE_NOT_USED(type);
@ -233,6 +244,10 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
return REDISMODULE_ERR;
}
if(RedisModule_SubscribeToKeyspaceEvents(ctx, REDISMODULE_NOTIFY_EXPIRED, KeySpace_NotificationExpired) != REDISMODULE_OK){
return REDISMODULE_ERR;
}
if(RedisModule_SubscribeToKeyspaceEvents(ctx, REDISMODULE_NOTIFY_MODULE, KeySpace_NotificationModule) != REDISMODULE_OK){
return REDISMODULE_ERR;
}

View File

@ -83,6 +83,17 @@ tags "modules" {
$rd1 close
}
test {Test expired key space event} {
set prev_expired [s expired_keys]
r set exp 1 PX 10
wait_for_condition 100 10 {
[s expired_keys] eq $prev_expired + 1
} else {
fail "key not expired"
}
assert_equal [r get testkeyspace:expired] 1
}
test "Unload the module - testkeyspace" {
assert_equal {OK} [r module unload testkeyspace]
}

View File

@ -108,10 +108,16 @@ tags "modules" {
{set asdf3 3 PXAT *}
{exec}
{incr notifications}
{incr notifications}
{incr testkeyspace:expired}
{del asdf*}
{incr notifications}
{incr notifications}
{incr testkeyspace:expired}
{del asdf*}
{incr notifications}
{incr notifications}
{incr testkeyspace:expired}
{del asdf*}
}
close_replication_stream $repl