Skip to content

Commit 8451992

Browse files
DOC-5289 added command reliability to node-redis prod usage
1 parent 27c180e commit 8451992

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

content/develop/clients/nodejs/produsage.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ progress in implementing the recommendations.
2727
{{< checklist "nodeprodlist" >}}
2828
{{< checklist-item "#handling-errors" >}}Handling errors{{< /checklist-item >}}
2929
{{< checklist-item "#handling-reconnections" >}}Handling reconnections{{< /checklist-item >}}
30-
{{< checklist-item "#timeouts" >}}Timeouts{{< /checklist-item >}}
30+
{{< checklist-item "#connection-timeouts" >}}Connection timeouts{{< /checklist-item >}}
31+
{{< checklist-item "#command-execution-reliability" >}}Command execution reliability{{< /checklist-item >}}
3132
{{< /checklist >}}
3233

3334
## Recommendations
@@ -63,10 +64,12 @@ own custom strategy. See
6364
[Reconnect after disconnection]({{< relref "/develop/clients/nodejs/connect#reconnect-after-disconnection" >}})
6465
for more information.
6566

66-
### Timeouts
67+
### Connection timeouts
6768

68-
To set a timeout for a connection, use the `connectTimeout` option:
69-
```typescript
69+
To set a timeout for a connection, use the `connectTimeout` option
70+
(the default timeout is 5 seconds):
71+
72+
```js
7073
const client = createClient({
7174
socket: {
7275
// setting a 10-second timeout
@@ -76,5 +79,29 @@ const client = createClient({
7679
client.on('error', error => console.error('Redis client error:', error));
7780
```
7881

79-
### Retries
82+
### Command execution reliability
83+
84+
By default, `node-redis` reconnects automatically when the connection is lost
85+
(but see [Handling reconnections](#handling-reconnections), if you want to
86+
customize this behavior). While the connection is down, any commands that you
87+
execute will be queued and sent to the server when the connection is restored.
88+
This might occasionally cause problems if the connection fails while a
89+
[non-idempotent](https://en.wikipedia.org/wiki/Idempotence) command
90+
is being executed. In this case, the command could change the data on the server
91+
without the client removing it from the queue. When the connection is restored,
92+
the command will be sent again, resulting in incorrect data.
93+
94+
If you need to avoid this situation, set the `disableOfflineQueue` option
95+
to `true` when you create the client. This will cause the client to discard
96+
unexecuted commands rather than queuing them:
97+
98+
```js
99+
const client = createClient({
100+
disableOfflineQueue: true,
101+
.
102+
.
103+
});
104+
```
80105

106+
Use a separate connection with the queue disabled if you want to avoid queuing
107+
only for specific commands.

0 commit comments

Comments
 (0)