MCPcopy
hub / github.com/redis/ioredis / connect

Method connect

lib/cluster/index.ts:191–306  ·  view source on GitHub ↗

* Connect to a cluster

()

Source from the content-addressed store, hash-verified

189 * Connect to a cluster
190 */
191 connect(): Promise<void> {
192 return new Promise((resolve, reject) => {
193 if (
194 this.status === "connecting" ||
195 this.status === "connect" ||
196 this.status === "ready"
197 ) {
198 reject(new Error("Redis is already connecting/connected"));
199 return;
200 }
201
202 const epoch = ++this.connectionEpoch;
203 this.setStatus("connecting");
204
205 this.resolveStartupNodeHostnames()
206 .then((nodes) => {
207 if (this.connectionEpoch !== epoch) {
208 debug(
209 "discard connecting after resolving startup nodes because epoch not match: %d != %d",
210 epoch,
211 this.connectionEpoch
212 );
213 reject(
214 new RedisError(
215 "Connection is discarded because a new connection is made"
216 )
217 );
218 return;
219 }
220 if (this.status !== "connecting") {
221 debug(
222 "discard connecting after resolving startup nodes because the status changed to %s",
223 this.status
224 );
225 reject(new RedisError("Connection is aborted"));
226 return;
227 }
228 this.connectionPool.reset(nodes);
229
230 if (this.options.shardedSubscribers) {
231 this.shardedSubscribers
232 .reset(this.slots, this.connectionPool.getNodes("all"))
233 .catch((err) => {
234 // TODO should we emit an error event here?
235 debug("Error while starting subscribers: %s", err);
236 });
237 }
238
239 const readyHandler = () => {
240 this.setStatus("ready");
241 this.retryAttempts = 0;
242 this.executeOfflineCommands();
243 this.resetNodesRefreshInterval();
244 resolve();
245 };
246
247 let closeListener: () => void = undefined;
248 const refreshListener = () => {

Callers 5

constructorMethod · 0.95
sendCommandMethod · 0.95
handleCloseEventMethod · 0.95
closeHandlerFunction · 0.45
startMethod · 0.45

Calls 10

setStatusMethod · 0.95
refreshSlotsCacheMethod · 0.95
handleCloseEventMethod · 0.95
getNodesMethod · 0.80
onceMethod · 0.80
resetMethod · 0.65
callMethod · 0.65
startMethod · 0.45

Tested by

no test coverage detected