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/produsage.md
+7-30Lines changed: 7 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -55,36 +55,13 @@ client.on('error', error => {
55
55
56
56
### Handling reconnections
57
57
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");
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
0 commit comments