MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / moduleNotifyKeyspaceEvent

Function moduleNotifyKeyspaceEvent

src/module.cpp:6112–6142  ·  view source on GitHub ↗

Dispatcher for keyspace notifications to module subscriber functions. * This gets called only if at least one module requested to be notified on * keyspace notifications */

Source from the content-addressed store, hash-verified

6110 * This gets called only if at least one module requested to be notified on
6111 * keyspace notifications */
6112void moduleNotifyKeyspaceEvent(int type, const char *event, robj *key, int dbid) {
6113 /* Don't do anything if there aren't any subscribers */
6114 if (listLength(moduleKeyspaceSubscribers) == 0) return;
6115
6116 listIter li;
6117 listNode *ln;
6118 listRewind(moduleKeyspaceSubscribers,&li);
6119
6120 /* Remove irrelevant flags from the type mask */
6121 type &= ~(NOTIFY_KEYEVENT | NOTIFY_KEYSPACE);
6122
6123 while((ln = listNext(&li))) {
6124 RedisModuleKeyspaceSubscriber *sub = (RedisModuleKeyspaceSubscriber*)ln->value;
6125 /* Only notify subscribers on events matching they registration,
6126 * and avoid subscribers triggering themselves */
6127 if ((sub->event_mask & type) && sub->active == 0) {
6128 RedisModuleCtx ctx = REDISMODULE_CTX_INIT;
6129 ctx.module = sub->module;
6130 ctx.client = moduleFreeContextReusedClient;
6131 selectDb(ctx.client, dbid);
6132
6133 /* mark the handler as active to avoid reentrant loops.
6134 * If the subscriber performs an action triggering itself,
6135 * it will not be notified about it. */
6136 sub->active = 1;
6137 sub->notify_callback(&ctx, type, event, key);
6138 sub->active = 0;
6139 moduleFreeContext(&ctx);
6140 }
6141 }
6142}
6143
6144/* Unsubscribe any notification subscribers this module has upon unloading */
6145void moduleUnsubscribeNotifications(RedisModule *module) {

Callers 3

moduleLoadCallbackFunction · 0.85
processJobMethod · 0.85
notifyKeyspaceEventFunction · 0.85

Calls 4

listRewindFunction · 0.85
listNextFunction · 0.85
selectDbFunction · 0.85
moduleFreeContextFunction · 0.85

Tested by

no test coverage detected