Skip to content

Commit 6e969fa

Browse files
committed
Merge branch 'master' of github.com:redis/node-redis into sharded-pubsub
2 parents 97bf4bf + 6642278 commit 6e969fa

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import { createClient } from 'redis';
5353

5454
const client = createClient();
5555

56-
client.on('error', (err) => console.log('Redis Client Error', err));
56+
client.on('error', err => console.log('Redis Client Error', err));
5757

5858
await client.connect();
5959

docs/client-configuration.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,31 @@
3030
## Reconnect Strategy
3131

3232
TODO: `false | number | (retries: number, cause: unknown) => number | Error`
33-
https://github.com/redis/node-redis/pull/2250
3433

3534
You can implement a custom reconnect strategy as a function:
35+
When a network error occurs the client will automatically try to reconnect, following a default linear strategy (the more attempts, the more waiting before trying to reconnect).
36+
37+
This strategy can be overridden by providing a `socket.reconnectStrategy` option during the client's creation.
38+
39+
The `socket.reconnectStrategy` is a function that:
3640

3741
- Receives the number of retries attempted so far and the causing error.
3842
- Returns `number | Error`:
3943
- `number`: wait time in milliseconds prior to attempting a reconnect.
4044
- `Error`: closes the client and flushes internal command queues.
4145

46+
The example below shows the default `reconnectStrategy` and how to override it.
47+
48+
```typescript
49+
import { createClient } from 'redis';
50+
51+
const client = createClient({
52+
socket: {
53+
reconnectStrategy: retries => Math.min(retries * 50, 500)
54+
}
55+
});
56+
```
57+
4258
## TLS
4359

4460
To enable TLS, set `socket.tls` to `true`. Below are some basic examples.

0 commit comments

Comments
 (0)