diff options
author | Salvatore Sanfilippo <antirez@gmail.com> | 2019-10-28 12:16:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-28 12:16:04 +0100 |
commit | 469a6e5f1a07463d46c7a258a4ea59a8da9348ec (patch) | |
tree | c80b316acf3dabaae2a88dcaef70b4031b7ff9a8 /src/module.c | |
parent | cfcb475435a9efb3de794e93103b931d16e3a959 (diff) | |
parent | cee6dead3c66530e8bf0b6cea455e3451d1fd0c7 (diff) | |
download | redis-469a6e5f1a07463d46c7a258a4ea59a8da9348ec.tar.gz |
Merge pull request #6481 from guybe7/modules_notify
Modules: Allow notifying custom keyspace events
Diffstat (limited to 'src/module.c')
-rw-r--r-- | src/module.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/module.c b/src/module.c index 971bf5c08..55568aca8 100644 --- a/src/module.c +++ b/src/module.c @@ -3859,6 +3859,11 @@ const RedisModuleString *RM_GetKeyNameFromIO(RedisModuleIO *io) { return io->key; } +/* Returns a RedisModuleString with the name of the key from RedisModuleKey */ +const RedisModuleString *RM_GetKeyNameFromModuleKey(RedisModuleKey *key) { + return key ? key->key : NULL; +} + /* -------------------------------------------------------------------------- * Logging * -------------------------------------------------------------------------- */ @@ -4368,6 +4373,20 @@ int RM_SubscribeToKeyspaceEvents(RedisModuleCtx *ctx, int types, RedisModuleNoti return REDISMODULE_OK; } +/* Get the configured bitmap of notify-keyspace-events (Could be used + * for additional filtering in RedisModuleNotificationFunc) */ +int RM_GetNotifyKeyspaceEvents() { + return server.notify_keyspace_events; +} + +/* Expose notifyKeyspaceEvent to modules */ +int RM_NotifyKeyspaceEvent(RedisModuleCtx *ctx, int type, const char *event, RedisModuleString *key) { + if (!ctx || !ctx->client) + return REDISMODULE_ERR; + notifyKeyspaceEvent(type, (char *)event, key, ctx->client->db->id); + return REDISMODULE_OK; +} + /* Dispatcher for keyspace notifications to module subscriber functions. * This gets called only if at least one module requested to be notified on * keyspace notifications */ @@ -6471,6 +6490,7 @@ void moduleRegisterCoreAPI(void) { REGISTER_API(StringCompare); REGISTER_API(GetContextFromIO); REGISTER_API(GetKeyNameFromIO); + REGISTER_API(GetKeyNameFromModuleKey); REGISTER_API(BlockClient); REGISTER_API(UnblockClient); REGISTER_API(IsBlockedReplyRequest); @@ -6485,6 +6505,8 @@ void moduleRegisterCoreAPI(void) { REGISTER_API(DigestAddStringBuffer); REGISTER_API(DigestAddLongLong); REGISTER_API(DigestEndSequence); + REGISTER_API(NotifyKeyspaceEvent); + REGISTER_API(GetNotifyKeyspaceEvents); REGISTER_API(SubscribeToKeyspaceEvents); REGISTER_API(RegisterClusterMessageReceiver); REGISTER_API(SendClusterMessage); |