summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2019-10-23 10:22:46 +0200
committerantirez <antirez@gmail.com>2019-10-23 10:22:46 +0200
commite3e9c303bb92e50feff019aa0fe74308ab8933be (patch)
treef99d0ccb850cbb28c7ac7543cbacad1f2c48479d
parent999728b792aae52c4264e9191c4572021195ea5d (diff)
downloadredis-e3e9c303bb92e50feff019aa0fe74308ab8933be.tar.gz
Modules hooks: implement the FLUSHDB event.
-rw-r--r--src/db.c13
-rw-r--r--src/module.c4
-rw-r--r--src/redismodule.h3
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 51cb477af..7ee55714e 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)