summaryrefslogtreecommitdiff
path: root/src/modules/hellohook.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2019-10-23 10:37:04 +0200
committerantirez <antirez@gmail.com>2019-10-23 18:39:53 +0200
commitbc1ef48e5667d945d920ca8da7dd7f799148991d (patch)
tree3f927a77d2ff6bb2b196185a9e464891bd148005 /src/modules/hellohook.c
parented833c9f99c01cf2c780a870c91924747ee4450d (diff)
downloadredis-bc1ef48e5667d945d920ca8da7dd7f799148991d.tar.gz
Modules hooks: FLUSHDB event example.
Diffstat (limited to 'src/modules/hellohook.c')
-rw-r--r--src/modules/hellohook.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/modules/hellohook.c b/src/modules/hellohook.c
index ea0ac517d..2e798f500 100644
--- a/src/modules/hellohook.c
+++ b/src/modules/hellohook.c
@@ -50,6 +50,31 @@ void clientChangeCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub,
ci->id,ci->addr,ci->port);
}
+void flushdbCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void *data)
+{
+ REDISMODULE_NOT_USED(ctx);
+ REDISMODULE_NOT_USED(e);
+
+ RedisModuleFlushInfo *fi = data;
+ if (sub == REDISMODULE_SUBEVENT_FLUSHDB_START) {
+ if (fi->dbnum != -1) {
+ RedisModuleCallReply *reply;
+ reply = RedisModule_Call(ctx,"DBSIZE","");
+ long long numkeys = RedisModule_CallReplyInteger(reply);
+ printf("FLUSHDB event of database %d started (%lld keys in DB)\n",
+ fi->dbnum, numkeys);
+ } else {
+ printf("FLUSHALL event started\n");
+ }
+ } else {
+ if (fi->dbnum != -1) {
+ printf("FLUSHDB event of database %d ended\n",fi->dbnum);
+ } else {
+ printf("FLUSHALL event ended\n");
+ }
+ }
+}
+
/* This function must be present on each Redis module. It is used in order to
* register the commands into the Redis server. */
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
@@ -61,5 +86,7 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
RedisModule_SubscribeToServerEvent(ctx,
RedisModuleEvent_ClientChange, clientChangeCallback);
+ RedisModule_SubscribeToServerEvent(ctx,
+ RedisModuleEvent_FlushDB, flushdbCallback);
return REDISMODULE_OK;
}