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

Function pubsubPublishMessage

app/redis-6.2.6/src/pubsub.c:288–332  ·  view source on GitHub ↗

Publish a message */

Source from the content-addressed store, hash-verified

286
287/* Publish a message */
288int pubsubPublishMessage(robj *channel, robj *message) {
289 int receivers = 0;
290 dictEntry *de;
291 dictIterator *di;
292 listNode *ln;
293 listIter li;
294
295 /* Send to clients listening for that channel */
296 de = dictFind(server.pubsub_channels,channel);
297 if (de) {
298 list *list = dictGetVal(de);
299 listNode *ln;
300 listIter li;
301
302 listRewind(list,&li);
303 while ((ln = listNext(&li)) != NULL) {
304 client *c = ln->value;
305 addReplyPubsubMessage(c,channel,message);
306 receivers++;
307 }
308 }
309 /* Send to clients listening to matching channels */
310 di = dictGetIterator(server.pubsub_patterns);
311 if (di) {
312 channel = getDecodedObject(channel);
313 while((de = dictNext(di)) != NULL) {
314 robj *pattern = dictGetKey(de);
315 list *clients = dictGetVal(de);
316 if (!stringmatchlen((char*)pattern->ptr,
317 sdslen(pattern->ptr),
318 (char*)channel->ptr,
319 sdslen(channel->ptr),0)) continue;
320
321 listRewind(clients,&li);
322 while ((ln = listNext(&li)) != NULL) {
323 client *c = listNodeValue(ln);
324 addReplyPubsubPatMessage(c,pattern,channel,message);
325 receivers++;
326 }
327 }
328 decrRefCount(channel);
329 dictReleaseIterator(di);
330 }
331 return receivers;
332}
333
334/*-----------------------------------------------------------------------------
335 * Pubsub commands implementation

Callers 5

publishCommandFunction · 0.85
sentinelEventFunction · 0.85
notifyKeyspaceEventFunction · 0.85
clusterProcessPacketFunction · 0.85
RM_PublishMessageFunction · 0.85

Calls 12

listRewindFunction · 0.85
listNextFunction · 0.85
addReplyPubsubMessageFunction · 0.85
getDecodedObjectFunction · 0.85
stringmatchlenFunction · 0.85
sdslenFunction · 0.85
addReplyPubsubPatMessageFunction · 0.85
decrRefCountFunction · 0.85
dictFindFunction · 0.70
dictGetIteratorFunction · 0.70
dictNextFunction · 0.70
dictReleaseIteratorFunction · 0.70

Tested by

no test coverage detected