MCPcopy
hub / github.com/redis/node-redis / constructor

Method constructor

packages/client/lib/client/index.ts:678–734  ·  view source on GitHub ↗
(options?: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING>)

Source from the content-addressed store, hash-verified

676 }
677
678 constructor(options?: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING>) {
679 super();
680 this.#validateOptions(options)
681 this.#options = this.#initiateOptions(options);
682
683 const socketOpts = this.#options.socket as { host?: string; port?: number } | undefined;
684 this.#clientIdentity = {
685 id: generateClientId(socketOpts?.host, socketOpts?.port, this.#selectedDB),
686 role: ClientRole.STANDALONE
687 };
688
689 this.#queue = this.#initiateQueue(this.#clientIdentity.id);
690 this.#socket = this.#initiateSocket(this.#clientIdentity.id);
691
692 this.#registerForMetrics();
693
694 if(this.#options.maintNotifications !== 'disabled') {
695 new EnterpriseMaintenanceManager(this.#queue, this, this.#options);
696 };
697
698 if (this.#options.clientSideCache) {
699 if (this.#options.clientSideCache instanceof ClientSideCacheProvider) {
700 this.#clientSideCache = this.#options.clientSideCache;
701 } else {
702 const cscConfig = this.#options.clientSideCache;
703 this.#clientSideCache = new BasicClientSideCache(cscConfig);
704 }
705 // eslint-disable-next-line @typescript-eslint/no-explicit-any
706 this.#queue.addPushHandler((push: Array<any>): boolean => {
707 if (push[0].toString() !== 'invalidate') return false;
708
709 if (push[1] !== null) {
710 for (const key of push[1]) {
711 this.#clientSideCache?.invalidate(key)
712 }
713 } else {
714 this.#clientSideCache?.invalidate(null)
715 }
716
717 return true
718 });
719 } else if (options?.emitInvalidate) {
720 // eslint-disable-next-line @typescript-eslint/no-explicit-any
721 this.#queue.addPushHandler((push: Array<any>): boolean => {
722 if (push[0].toString() !== 'invalidate') return false;
723
724 if (push[1] !== null) {
725 for (const key of push[1]) {
726 this.emit('invalidate', key);
727 }
728 } else {
729 this.emit('invalidate', null);
730 }
731 return true
732 });
733 }
734 }
735

Callers

nothing calls this directly

Calls 9

#validateOptionsMethod · 0.95
#initiateOptionsMethod · 0.95
#initiateQueueMethod · 0.95
#initiateSocketMethod · 0.95
#registerForMetricsMethod · 0.95
generateClientIdFunction · 0.90
addPushHandlerMethod · 0.80
toStringMethod · 0.65
invalidateMethod · 0.65

Tested by

no test coverage detected