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

Function pubsubCommand

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

PUBSUB command for Pub/Sub introspection. */

Source from the content-addressed store, hash-verified

413
414/* PUBSUB command for Pub/Sub introspection. */
415void pubsubCommand(client *c) {
416 if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"help")) {
417 const char *help[] = {
418"CHANNELS [<pattern>]",
419" Return the currently active channels matching a <pattern> (default: '*').",
420"NUMPAT",
421" Return number of subscriptions to patterns.",
422"NUMSUB [<channel> ...]",
423" Return the number of subscribers for the specified channels, excluding",
424" pattern subscriptions(default: no channels).",
425NULL
426 };
427 addReplyHelp(c, help);
428 } else if (!strcasecmp(c->argv[1]->ptr,"channels") &&
429 (c->argc == 2 || c->argc == 3))
430 {
431 /* PUBSUB CHANNELS [<pattern>] */
432 sds pat = (c->argc == 2) ? NULL : c->argv[2]->ptr;
433 dictIterator *di = dictGetIterator(server.pubsub_channels);
434 dictEntry *de;
435 long mblen = 0;
436 void *replylen;
437
438 replylen = addReplyDeferredLen(c);
439 while((de = dictNext(di)) != NULL) {
440 robj *cobj = dictGetKey(de);
441 sds channel = cobj->ptr;
442
443 if (!pat || stringmatchlen(pat, sdslen(pat),
444 channel, sdslen(channel),0))
445 {
446 addReplyBulk(c,cobj);
447 mblen++;
448 }
449 }
450 dictReleaseIterator(di);
451 setDeferredArrayLen(c,replylen,mblen);
452 } else if (!strcasecmp(c->argv[1]->ptr,"numsub") && c->argc >= 2) {
453 /* PUBSUB NUMSUB [Channel_1 ... Channel_N] */
454 int j;
455
456 addReplyArrayLen(c,(c->argc-2)*2);
457 for (j = 2; j < c->argc; j++) {
458 list *l = dictFetchValue(server.pubsub_channels,c->argv[j]);
459
460 addReplyBulk(c,c->argv[j]);
461 addReplyLongLong(c,l ? listLength(l) : 0);
462 }
463 } else if (!strcasecmp(c->argv[1]->ptr,"numpat") && c->argc == 2) {
464 /* PUBSUB NUMPAT */
465 addReplyLongLong(c,dictSize(server.pubsub_patterns));
466 } else {
467 addReplySubcommandSyntaxError(c);
468 }
469}

Callers

nothing calls this directly

Calls 14

strcasecmpFunction · 0.85
addReplyHelpFunction · 0.85
addReplyDeferredLenFunction · 0.85
stringmatchlenFunction · 0.85
sdslenFunction · 0.85
addReplyBulkFunction · 0.85
setDeferredArrayLenFunction · 0.85
addReplyArrayLenFunction · 0.85
dictFetchValueFunction · 0.85
addReplyLongLongFunction · 0.85
dictGetIteratorFunction · 0.70

Tested by

no test coverage detected