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

Function notifyKeyspaceEvent

src/notify.cpp:101–142  ·  view source on GitHub ↗

The API provided to the rest of the Redis core is a simple function: * * notifyKeyspaceEvent(char *event, robj *key, int dbid); * * 'event' is a C string representing the event name. * 'key' is a Redis object representing the key name. * 'dbid' is the database ID where the key lives. */

Source from the content-addressed store, hash-verified

99 * 'key' is a Redis object representing the key name.
100 * 'dbid' is the database ID where the key lives. */
101void notifyKeyspaceEvent(int type, const char *event, robj *key, int dbid) {
102 sds chan;
103 robj *chanobj, *eventobj;
104 int len = -1;
105 char buf[24];
106
107 /* If any modules are interested in events, notify the module system now.
108 * This bypasses the notifications configuration, but the module engine
109 * will only call event subscribers if the event type matches the types
110 * they are interested in. */
111 moduleNotifyKeyspaceEvent(type, event, key, dbid);
112
113 /* If notifications for this class of events are off, return ASAP. */
114 if (!(g_pserver->notify_keyspace_events & type)) return;
115
116 eventobj = createStringObject(event,strlen(event));
117
118 /* __keyspace@<db>__:<key> <event> notifications. */
119 if (g_pserver->notify_keyspace_events & NOTIFY_KEYSPACE) {
120 chan = sdsnewlen("__keyspace@",11);
121 len = ll2string(buf,sizeof(buf),dbid);
122 chan = sdscatlen(chan, buf, len);
123 chan = sdscatlen(chan, "__:", 3);
124 chan = sdscatsds(chan, szFromObj(key));
125 chanobj = createObject(OBJ_STRING, chan);
126 pubsubPublishMessage(chanobj, eventobj);
127 decrRefCount(chanobj);
128 }
129
130 /* __keyevent@<db>__:<event> <key> notifications. */
131 if (g_pserver->notify_keyspace_events & NOTIFY_KEYEVENT) {
132 chan = sdsnewlen("__keyevent@",11);
133 if (len == -1) len = ll2string(buf,sizeof(buf),dbid);
134 chan = sdscatlen(chan, buf, len);
135 chan = sdscatlen(chan, "__:", 3);
136 chan = sdscatsds(chan, szFromObj(eventobj));
137 chanobj = createObject(OBJ_STRING, chan);
138 pubsubPublishMessage(chanobj, key);
139 decrRefCount(chanobj);
140 }
141 decrRefCount(eventobj);
142}

Callers 15

lookupKeyReadWithFlagsFunction · 0.85
delGenericCommandFunction · 0.85
renameGenericCommandFunction · 0.85
moveCommandFunction · 0.85
copyCommandFunction · 0.85
mvccrestoreCommandFunction · 0.85
restoreCommandFunction · 0.85
migrateCommandFunction · 0.85
evictFunction · 0.85
sortCommandFunction · 0.85
hsetnxCommandFunction · 0.85

Calls 10

sdsnewlenFunction · 0.85
ll2stringFunction · 0.85
sdscatlenFunction · 0.85
sdscatsdsFunction · 0.85
szFromObjFunction · 0.85
createObjectFunction · 0.85
pubsubPublishMessageFunction · 0.85
decrRefCountFunction · 0.85
createStringObjectFunction · 0.70

Tested by

no test coverage detected