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

Method close

packages/client/lib/client/index.ts:1830–1854  ·  view source on GitHub ↗

* Close the client. Wait for pending commands.

()

Source from the content-addressed store, hash-verified

1828 * Close the client. Wait for pending commands.
1829 */
1830 close() {
1831 return new Promise<void>(resolve => {
1832 clearTimeout(this._self.#pingTimer);
1833 this._self.#socket.close();
1834 this._self.#clientSideCache?.onClose();
1835
1836 if (this._self.#queue.isEmpty()) {
1837 this._self.#unregisterFromMetrics();
1838 this._self.#socket.destroySocket();
1839 return resolve();
1840 }
1841
1842 const maybeClose = () => {
1843 if (!this._self.#queue.isEmpty()) return;
1844
1845 this._self.#socket.off('data', maybeClose);
1846 this._self.#unregisterFromMetrics();
1847 this._self.#socket.destroySocket();
1848 resolve();
1849 };
1850 this._self.#socket.on('data', maybeClose);
1851 this._self.#credentialsSubscription?.dispose();
1852 this._self.#credentialsSubscription = null;
1853 });
1854 }
1855
1856 /**
1857 * Destroy the client. Rejects all commands immediately.

Callers 15

pool.spec.tsFile · 0.45
cache.spec.tsFile · 0.45
withConnectedSocketFunction · 0.45
withCapturedConnectFunction · 0.45
index.spec.tsFile · 0.45
setupFunction · 0.45
onEventFunction · 0.45
spawnRedisSentinelFunction · 0.45
stopMethod · 0.45
getFreePortNumberFunction · 0.45
cmds-cnxmgmt.jsFile · 0.45
cmds-generic.jsFile · 0.45

Calls 5

isEmptyMethod · 0.80
destroySocketMethod · 0.80
disposeMethod · 0.80
onCloseMethod · 0.45

Tested by 3

withConnectedSocketFunction · 0.36
withCapturedConnectFunction · 0.36
setupFunction · 0.36