MCPcopy Create free account
hub / github.com/F-Stack/f-stack / notifyKeyspaceEvent

Function notifyKeyspaceEvent

app/redis-6.2.6/src/notify.c: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, 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 (!(server.notify_keyspace_events & type)) return;
115
116 eventobj = createStringObject(event,strlen(event));
117
118 /* __keyspace@<db>__:<key> <event> notifications. */
119 if (server.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, key->ptr);
125 chanobj = createObject(OBJ_STRING, chan);
126 pubsubPublishMessage(chanobj, eventobj);
127 decrRefCount(chanobj);
128 }
129
130 /* __keyevent@<db>__:<event> <key> notifications. */
131 if (server.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, eventobj->ptr);
137 chanobj = createObject(OBJ_STRING, chan);
138 pubsubPublishMessage(chanobj, key);
139 decrRefCount(chanobj);
140 }
141 decrRefCount(eventobj);
142}

Callers 15

expireGenericCommandFunction · 0.85
persistCommandFunction · 0.85
hsetnxCommandFunction · 0.85
hsetCommandFunction · 0.85
hincrbyCommandFunction · 0.85
hincrbyfloatCommandFunction · 0.85
hdelCommandFunction · 0.85
georadiusGenericFunction · 0.85
setGenericCommandFunction · 0.85
getexCommandFunction · 0.85
getdelCommandFunction · 0.85

Calls 9

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

Tested by

no test coverage detected