You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`connect`| The client is initiating a connection to the server. |_No argument_|
379
-
|`ready`| The client successfully initiated the connection to the server. |_No argument_|
380
-
|`end`| The client disconnected the connection to the server via `.quit()` or `.disconnect()`. |_No argument_|
381
-
|`error`| When a network error has occurred, such as unable to connect to the server or the connection closed unexpectedly. | 1 argument: The error object, such as `SocketClosedUnexpectedlyError: Socket closed unexpectedly` or `Error: connect ECONNREFUSED [IP]:[PORT]`|
382
-
|`reconnecting`| The client is trying to reconnect to the server. |_No argument_|
383
-
384
-
The client will not emit [any other events](./docs/v3-to-v4.md#all-the-removed-events) beyond those listed above.
|`connect`| Initiating a connection to the server |*No arguments*|
379
+
|`ready`| Client is ready to use |*No arguments*|
380
+
|`end`| Connection has been closed (via `.quit()` or `.disconnect()`) |*No arguments*|
381
+
|`error`| An error has occurred—usually a network issue such as "Socket closed unexpectedly" |`(error: Error)`|
382
+
|`reconnecting`| Client is trying to reconnect to the server |*No arguments*|
383
+
|`sharded-channel-moved`| The ["cluster slot"](https://redis.io/docs/reference/cluster-spec/#key-distribution-model) of a subscribed [sharded PubSub](https://redis.io/docs/manual/pubsub/#sharded-pubsub) channel has been moved |`(channel: string, listeners: { buffers: Set<Listener<Buffer>>, strings: Set<Listener<string>> })`|
384
+
385
+
> :warning: You **MUST** listen to `error` events. If a client doesn't have at least one `error` listener registered and an `error` occurs, that error will be thrown and the Node.js process will exit. See the [`EventEmitter` docs](https://nodejs.org/api/events.html#events_error_events) for more details.
386
+
387
+
> The client will not emit [any other events](./docs/v3-to-v4.md#all-the-removed-events) beyond those listed above.
Copy file name to clipboardExpand all lines: docs/client-configuration.md
+9-17Lines changed: 9 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -29,26 +29,18 @@
29
29
30
30
## Reconnect Strategy
31
31
32
-
When a network error occurs the client will automatically try to reconnect, following a default linear strategy (the more attempts, the more waiting before trying to reconnect).
32
+
When the socket closes unexpectedly (without calling `.quit()`/`.disconnect()`) the client uses `reconnectStrategy` to decide what to do:
33
+
1.`false` -> do not reconnect, close the client and flush all commands in the queue.
34
+
2.`number` -> wait for `X` milliseconds before reconnecting.
35
+
3.`(retries: number, cause: Error) => number | Error` -> `number` is the same as configuration a `number` directly, `Error` is the same as `false`, but with a custom error.
33
36
34
-
This strategy can be overridden by providing a `socket.reconnectStrategy` option during the client's creation.
35
-
36
-
The `socket.reconnectStrategy` is a function that:
37
-
38
-
- Receives the number of retries attempted so far.
39
-
- Returns `number | Error`:
40
-
-`number`: wait time in milliseconds prior to attempting a reconnect.
41
-
-`Error`: closes the client and flushes internal command queues.
42
-
43
-
The example below shows the default `reconnectStrategy` and how to override it.
37
+
By default the strategy is `Math.min(retries * 50, 500)`, but it can be overriten:
Copy file name to clipboardExpand all lines: docs/clustering.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,7 @@ const value = await cluster.get('key');
35
35
| rootNodes || An array of root nodes that are part of the cluster, which will be used to get the cluster topology. Each element in the array is a client configuration object. There is no need to specify every node in the cluster, 3 should be enough to reliably connect and obtain the cluster configuration from the server |
36
36
| defaults || The default configuration values for every client in the cluster. Use this for example when specifying an ACL user to connect with |
37
37
| useReplicas |`false`| When `true`, distribute load by executing readonly commands (such as `GET`, `GEOSEARCH`, etc.) across all cluster nodes. When `false`, only use master nodes |
38
+
| minimizeConnections |`false`| When `true`, `.connect()` will only discover the cluster topology, without actually connecting to all the nodes. Useful for short-term or PubSub-only connections. |
38
39
| maxCommandRedirections |`16`| The maximum number of times a command will be redirected due to `MOVED` or `ASK` errors |
39
40
| nodeAddressMap || Defines the [node address mapping](#node-address-map)|
40
41
| modules || Included [Redis Modules](../README.md#packages)|
0 commit comments