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. */
| 99 | * 'key' is a Redis object representing the key name. |
| 100 | * 'dbid' is the database ID where the key lives. */ |
| 101 | void 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 | } |
no test coverage detected