Modules hooks: test flush event.

This commit is contained in:
antirez 2019-10-24 10:51:03 +02:00
parent 39f2ab595c
commit 6e98214f74
3 changed files with 17 additions and 3 deletions

View File

@ -5882,6 +5882,8 @@ void moduleFireServerEvent(uint64_t eid, int subid, void *data) {
* sense. For instance for FLUSHDB events we select the correct
* DB automatically. */
selectDb(ctx.client, 0);
/* Event specific context and data pointer setup. */
if (eid == REDISMODULE_EVENT_CLIENT_CHANGE) {
modulePopulateClientInfoStructure(&civ1,data,
el->event.dataver);

View File

@ -43,6 +43,7 @@ void clientChangeCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub,
char *keyname = (sub == REDISMODULE_SUBEVENT_CLIENT_CHANGE_CONNECTED) ?
"connected" : "disconnected";
RedisModuleCallReply *reply;
RedisModule_SelectDb(ctx,9);
reply = RedisModule_Call(ctx,"RPUSH","cl",keyname,(long)ci->id);
RedisModule_FreeCallReply(reply);
}
@ -56,6 +57,7 @@ void flushdbCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void
char *keyname = (sub == REDISMODULE_SUBEVENT_FLUSHDB_START) ?
"flush-start" : "flush-end";
RedisModuleCallReply *reply;
RedisModule_SelectDb(ctx,9);
reply = RedisModule_Call(ctx,"RPUSH","cl",keyname,(long)fi->dbnum);
RedisModule_FreeCallReply(reply);
}

View File

@ -8,11 +8,21 @@ tags "modules" {
set rd1 [redis_deferring_client]
$rd1 close
}
r select 0
puts "Keys: [r keys *]"
assert {[r llen connected] > 1}
assert {[r llen disconnected] > 1}
}
test {Test flushdb hooks} {
r flushall ;# Note: only the "end" RPUSH will survive
r select 1
r flushdb
r select 2
r flushdb
r select 9
assert {[r llen flush-start] == 2}
assert {[r llen flush-end] == 3}
assert {[r lrange flush-start 0 -1] eq {1 2}}
assert {[r lrange flush-end 0 -1] eq {-1 1 2}}
}
}
}