Skip to content

Commit c93b216

Browse files
Merge pull request #1523 from redis/DOC-5193-node-js-prod-usage
DOC-5193 reviewed node-redis production usage page
2 parents 48b4780 + 9f666dc commit c93b216

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

content/develop/clients/nodejs/produsage.md

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,22 @@ title: Production usage
1515
weight: 5
1616
---
1717

18-
The following sections explain how to handle situations that may occur
19-
in your production environment.
18+
This guide offers recommendations to get the best reliability and
19+
performance in your production environment.
20+
21+
## Checklist
22+
23+
Each item in the checklist below links to the section
24+
for a recommendation. Use the checklist icons to record your
25+
progress in implementing the recommendations.
26+
27+
{{< checklist "nodeprodlist" >}}
28+
{{< checklist-item "#handling-errors" >}}Handling errors{{< /checklist-item >}}
29+
{{< checklist-item "#handling-reconnections" >}}Handling reconnections{{< /checklist-item >}}
30+
{{< checklist-item "#timeouts" >}}Timeouts{{< /checklist-item >}}
31+
{{< /checklist >}}
32+
33+
## Recommendations
2034

2135
### Handling errors
2236

@@ -41,36 +55,13 @@ client.on('error', error => {
4155

4256
### Handling reconnections
4357

44-
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.
45-
The rest of the pending commands will remain queued in memory until a new socket is established.
46-
This behaviour is controlled by the `enableOfflineQueue` option, which is enabled by default.
47-
48-
The client uses `reconnectStrategy` to decide when to attempt to reconnect.
49-
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:
50-
51-
52-
1. Define a callback `(retries: number, cause: Error) => false | number | Error` **(recommended)**
53-
```typescript
54-
const client = createClient({
55-
socket: {
56-
reconnectStrategy: function(retries) {
57-
if (retries > 20) {
58-
console.log("Too many attempts to reconnect. Redis connection was terminated");
59-
return new Error("Too many retries.");
60-
} else {
61-
return retries * 500;
62-
}
63-
}
64-
}
65-
});
66-
client.on('error', error => console.error('Redis client error:', error));
67-
```
68-
In the provided reconnection strategy callback, the client attempts to reconnect up to 20 times with a delay of `retries * 500` milliseconds between attempts.
69-
After approximately two minutes, the client logs an error message and terminates the connection if the maximum retry limit is exceeded.
70-
71-
72-
2. Use a numerical value to set a fixed delay in milliseconds.
73-
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.
7465

7566
### Timeouts
7667

0 commit comments

Comments
 (0)