Skip to content

Commit 9f666dc

Browse files
DOC-5193 added suggestion from feedback
1 parent d31bb26 commit 9f666dc

File tree

1 file changed

+7
-30
lines changed

1 file changed

+7
-30
lines changed

content/develop/clients/nodejs/produsage.md

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,36 +55,13 @@ client.on('error', error => {
5555

5656
### Handling reconnections
5757

58-
If network issues or other problems unexpectedly close the socket, the client will reject all commands already sent, since the server might have already executed them.
59-
The rest of the pending commands will remain queued in memory until a new socket is established.
60-
This behaviour is controlled by the `enableOfflineQueue` option, which is enabled by default.
61-
62-
The client uses `reconnectStrategy` to decide when to attempt to reconnect.
63-
The default strategy is to calculate the delay before each attempt based on the attempt number `Math.min(retries * 50, 500)`. You can customize this strategy by passing a supported value to `reconnectStrategy` option:
64-
65-
66-
1. Define a callback `(retries: number, cause: Error) => false | number | Error` **(recommended)**
67-
```typescript
68-
const client = createClient({
69-
socket: {
70-
reconnectStrategy: function(retries) {
71-
if (retries > 20) {
72-
console.log("Too many attempts to reconnect. Redis connection was terminated");
73-
return new Error("Too many retries.");
74-
} else {
75-
return retries * 500;
76-
}
77-
}
78-
}
79-
});
80-
client.on('error', error => console.error('Redis client error:', error));
81-
```
82-
In the provided reconnection strategy callback, the client attempts to reconnect up to 20 times with a delay of `retries * 500` milliseconds between attempts.
83-
After approximately two minutes, the client logs an error message and terminates the connection if the maximum retry limit is exceeded.
84-
85-
86-
2. Use a numerical value to set a fixed delay in milliseconds.
87-
3. Use `false` to disable reconnection attempts. This option should only be used for testing purposes.
58+
When the socket closes unexpectedly (without calling the `quit()` or `disconnect()` methods),
59+
the client can automatically restore the connection. A simple
60+
[exponential backoff](https://en.wikipedia.org/wiki/Exponential_backoff) strategy
61+
for reconnection is enabled by default, but you can replace this with your
62+
own custom strategy. See
63+
[Reconnect after disconnection]({{< relref "/develop/clients/nodejs/connect#reconnect-after-disconnection" >}})
64+
for more information.
8865

8966
### Timeouts
9067

0 commit comments

Comments
 (0)