MCPcopy
hub / github.com/redis/node-redis / #emitPubSubMessage

Method #emitPubSubMessage

packages/client/lib/client/pub-sub.ts:450–483  ·  view source on GitHub ↗
(
    type: PubSubType,
    message: Buffer,
    channel: Buffer,
    pattern?: Buffer
  )

Source from the content-addressed store, hash-verified

448 }
449
450 #emitPubSubMessage(
451 type: PubSubType,
452 message: Buffer,
453 channel: Buffer,
454 pattern?: Buffer
455 ): void {
456 const keyString = (pattern ?? channel).toString(),
457 listeners = this.listeners[type].get(keyString);
458
459 if (!listeners) return;
460
461 publish(CHANNELS.PUBSUB, () => ({
462 direction: 'in' as const,
463 clientId: this.#clientId,
464 channel,
465 sharded: type === PUBSUB_TYPE.SHARDED,
466 }));
467
468 for (const listener of listeners.buffers) {
469 listener(message, channel);
470 }
471
472 if (!listeners.strings.size) return;
473
474 const channelString = pattern ? channel.toString() : keyString,
475 messageString = channelString === '__redis__:invalidate' ?
476 // https://github.com/redis/redis/pull/7469
477 // https://github.com/redis/redis/issues/7463
478 (message === null ? null : (message as any as Array<Buffer>).map(x => x.toString())) as any :
479 message.toString();
480 for (const listener of listeners.strings) {
481 listener(messageString, channelString);
482 }
483 }
484}

Callers 1

handleMessageReplyMethod · 0.95

Calls 4

publishFunction · 0.90
listenerFunction · 0.70
toStringMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected