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

Method connect

test/helpers/mock_server.ts:67–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65 }
66
67 connect() {
68 this.socket = createServer((c) => {
69 const clientIndex = this.clients.push(c) - 1;
70 process.nextTick(() => {
71 this.emit("connect", c);
72 });
73
74 const parser = new Parser({
75 returnBuffers: true,
76 stringNumbers: false,
77 returnReply: (reply: any) => {
78 reply = convertBufferToString(reply, "utf8");
79 if (
80 reply.length === 3 &&
81 reply[0].toLowerCase() === "client" &&
82 reply[1].toLowerCase() === "setname"
83 ) {
84 connectionNameMap.set(c, reply[2]);
85 }
86 if (
87 this.slotTable &&
88 reply.length === 2 &&
89 reply[0].toLowerCase() === "cluster" &&
90 reply[1].toLowerCase() === "slots"
91 ) {
92 this.write(c, this.slotTable);
93 return;
94 }
95 const flags: Flags = {};
96 const handlerResult = this.handler && this.handler(reply, c, flags);
97 if (!flags.hang) {
98 this.write(c, handlerResult);
99 }
100 if (flags.disconnect) {
101 this.disconnect();
102 }
103 },
104 returnError: () => {},
105 });
106
107 c.on("end", () => {
108 this.clients[clientIndex] = null;
109 this.emit("disconnect", c);
110 });
111
112 c.on("data", (data) => {
113 parser.execute(data);
114 });
115 });
116
117 this.socket.listen(this.port);
118 enableDestroy(this.socket);
119 }
120
121 disconnect(callback?: () => void) {
122 // @ts-expect-error

Callers 15

constructorMethod · 0.95
connector.tsFile · 0.45
sentinel_nat.tsFile · 0.45
reconnectOnErrorFunction · 0.45
client_info.tsFile · 0.45
socketTimeout.tsFile · 0.45
sentinel.tsFile · 0.45
tls.tsFile · 0.45
ready_check.tsFile · 0.45
connection.tsFile · 0.45
tracing.tsFile · 0.45

Calls 7

writeMethod · 0.95
disconnectMethod · 0.95
convertBufferToStringFunction · 0.90
setMethod · 0.80
onMethod · 0.65
pushMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected