| 142 | } |
| 143 | |
| 144 | #createSocketFactory(options?: RedisSocketOptions) { |
| 145 | // TLS |
| 146 | if (options?.tls === true) { |
| 147 | const withDefaults: tls.ConnectionOptions = { |
| 148 | ...options, |
| 149 | port: options?.port ?? 6379, |
| 150 | // https://nodejs.org/api/tls.html#tlsconnectoptions-callback "Any socket.connect() option not already listed" |
| 151 | // @types/node is... incorrect... |
| 152 | // @ts-expect-error - @types/node omits socket.connect noDelay. |
| 153 | noDelay: options?.noDelay ?? true, |
| 154 | // @ts-expect-error - @types/node omits socket.connect keepAlive. |
| 155 | keepAlive: options?.keepAlive ?? true, |
| 156 | // @ts-expect-error - @types/node omits socket.connect keepAliveInitialDelay. |
| 157 | keepAliveInitialDelay: options?.keepAliveInitialDelay ?? DEFAULT_KEEPALIVE_INITIAL_DELAY, |
| 158 | timeout: undefined, |
| 159 | onread: undefined, |
| 160 | readable: true, |
| 161 | writable: true |
| 162 | }; |
| 163 | return { |
| 164 | create() { |
| 165 | return tls.connect(withDefaults); |
| 166 | }, |
| 167 | event: 'secureConnect' |
| 168 | }; |
| 169 | } |
| 170 | |
| 171 | // IPC |
| 172 | if (options && 'path' in options) { |
| 173 | const withDefaults: net.IpcNetConnectOpts = { |
| 174 | ...options, |
| 175 | timeout: undefined, |
| 176 | onread: undefined, |
| 177 | readable: true, |
| 178 | writable: true |
| 179 | }; |
| 180 | return { |
| 181 | create() { |
| 182 | return net.createConnection(withDefaults); |
| 183 | }, |
| 184 | event: 'connect' |
| 185 | }; |
| 186 | } |
| 187 | |
| 188 | // TCP |
| 189 | const withDefaults: net.TcpNetConnectOpts = { |
| 190 | ...options, |
| 191 | port: options?.port ?? 6379, |
| 192 | noDelay: options?.noDelay ?? true, |
| 193 | keepAlive: options?.keepAlive ?? true, |
| 194 | keepAliveInitialDelay: options?.keepAliveInitialDelay ?? DEFAULT_KEEPALIVE_INITIAL_DELAY, |
| 195 | timeout: undefined, |
| 196 | onread: undefined, |
| 197 | readable: true, |
| 198 | writable: true |
| 199 | }; |
| 200 | return { |
| 201 | create() { |