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
Copy file name to clipboardExpand all lines: content/develop/clients/nodejs/connect.md
+76-2Lines changed: 76 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,7 @@ createClient({
67
67
```
68
68
To check if the client is connected and ready to send commands, use `client.isReady`, which returns a Boolean. `client.isOpen` is also available. This returns `true` when the client's underlying socket is open, and `false` when it isn't (for example, when the client is still connecting or reconnecting after a network error).
69
69
70
-
###Connect to a Redis cluster
70
+
## Connect to a Redis cluster
71
71
72
72
To connect to a Redis cluster, use `createCluster`.
When you deploy your application, use TLS and follow the [Redis security]({{< relref "/operate/oss_and_stack/management/security/" >}}) guidelines.
103
103
@@ -127,3 +127,77 @@ await client.disconnect();
127
127
```
128
128
129
129
You can also use discrete parameters and UNIX sockets. Details can be found in the [client configuration guide](https://github.com/redis/node-redis/blob/master/docs/client-configuration.md).
130
+
131
+
## Reconnect after disconnection
132
+
133
+
By default, `node-redis` doesn't attempt to reconnect automatically when
134
+
the connection to the server is lost. However, you can set the
135
+
`socket.reconnectionStrategy` field in the configuration to decide
136
+
whether to try to reconnect and how to approach it. Choose one of the following values for
137
+
`socket.reconnectionStrategy`:
138
+
139
+
-`false`: (Default) Don't attempt to reconnect.
140
+
-`number`: Wait for this number of milliseconds and then attempt to reconnect.
141
+
-`<function>`: Use a custom
142
+
function to decide how to handle reconnection.
143
+
144
+
The custom function has the following signature:
145
+
146
+
```js
147
+
(retries:number, cause:Error) =>false| number |Error
148
+
```
149
+
150
+
It is called before each attempt to reconnect, with the `retries`
151
+
indicating how many attempts have been made so far. The `cause` parameter is an
0 commit comments