From ed833c9f99c01cf2c780a870c91924747ee4450d Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 23 Oct 2019 10:22:46 +0200 Subject: [PATCH] Modules hooks: implement the FLUSHDB event. --- src/db.c | 13 +++++++++++++ src/module.c | 4 ++-- src/redismodule.h | 3 +++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/db.c b/src/db.c index f7d3b71e8..2c0a0cdd3 100644 --- a/src/db.c +++ b/src/db.c @@ -350,6 +350,12 @@ long long emptyDbGeneric(redisDb *dbarray, int dbnum, int flags, void(callback)( return -1; } + /* Fire the flushdb modules event. */ + RedisModuleFlushInfoV1 fi = {REDISMODULE_FLUSHINFO_VERSION,!async,dbnum}; + moduleFireServerEvent(REDISMODULE_EVENT_FLUSHDB, + REDISMODULE_SUBEVENT_FLUSHDB_START, + &fi); + /* Make sure the WATCHed keys are affected by the FLUSH* commands. * Note that we need to call the function while the keys are still * there. */ @@ -380,6 +386,13 @@ long long emptyDbGeneric(redisDb *dbarray, int dbnum, int flags, void(callback)( } } if (dbnum == -1) flushSlaveKeysWithExpireList(); + + /* Also fire the end event. Note that this event will fire almost + * immediately after the start event if the flush is asynchronous. */ + moduleFireServerEvent(REDISMODULE_EVENT_FLUSHDB, + REDISMODULE_SUBEVENT_FLUSHDB_END, + &fi); + return removed; } diff --git a/src/module.c b/src/module.c index 8957849fd..f3fe4e9ac 100644 --- a/src/module.c +++ b/src/module.c @@ -5721,8 +5721,8 @@ void ModuleForkDoneHandler(int exitcode, int bysignal) { * because of replication, after the replica synchronization) * happened. The following sub events are available: * - * REDISMODULE_EVENT_FLUSHALL_START - * REDISMODULE_EVENT_FLUSHALL_END + * REDISMODULE_EVENT_FLUSHDB_START + * REDISMODULE_EVENT_FLUSHDB_END * * The data pointer can be casted to a RedisModuleFlushInfo * structure with the following fields: diff --git a/src/redismodule.h b/src/redismodule.h index d8f4fb901..377ea7e13 100644 --- a/src/redismodule.h +++ b/src/redismodule.h @@ -239,6 +239,9 @@ static RedisModuleEvent #define REDISMODULE_SUBEVENT_REPLICA_CHANGE_CONNECTED 0 #define REDISMODULE_SUBEVENT_REPLICA_CHANGE_DISCONNECTED 1 +#define REDISMODULE_SUBEVENT_FLUSHDB_START 0 +#define REDISMODULE_SUBEVENT_FLUSHDB_END 1 + /* RedisModuleClientInfo flags. */ #define REDISMODULE_CLIENTINFO_FLAG_SSL (1<<0) #define REDISMODULE_CLIENTINFO_FLAG_PUBSUB (1<<1)