diff options
author | antirez <antirez@gmail.com> | 2019-10-23 10:22:46 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2019-10-23 18:39:53 +0200 |
commit | ed833c9f99c01cf2c780a870c91924747ee4450d (patch) | |
tree | c862a657936c04a392527017b7bd57ec0c325c2d | |
parent | 8ec2fc3969b5f66fbcab82b7470ac36ec92f2ee9 (diff) | |
download | redis-ed833c9f99c01cf2c780a870c91924747ee4450d.tar.gz |
Modules hooks: implement the FLUSHDB event.
-rw-r--r-- | src/db.c | 13 | ||||
-rw-r--r-- | src/module.c | 4 | ||||
-rw-r--r-- | src/redismodule.h | 3 |
3 files changed, 18 insertions, 2 deletions
@@ -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) |