diff --git a/README.md b/README.md index 2a894f50c5..b06b7f3cfd 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ import { createClient } from 'redis'; const client = createClient(); -client.on('error', (err) => console.log('Redis Client Error', err)); +client.on('error', err => console.log('Redis Client Error', err)); await client.connect(); diff --git a/docs/client-configuration.md b/docs/client-configuration.md index a67cef462a..d57d0c5dd3 100644 --- a/docs/client-configuration.md +++ b/docs/client-configuration.md @@ -29,13 +29,29 @@ ## Reconnect Strategy -You can implement a custom reconnect strategy as a function: +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). + +This strategy can be overridden by providing a `socket.reconnectStrategy` option during the client's creation. + +The `socket.reconnectStrategy` is a function that: - Receives the number of retries attempted so far. - Returns `number | Error`: - `number`: wait time in milliseconds prior to attempting a reconnect. - `Error`: closes the client and flushes internal command queues. +The example below shows the default `reconnectStrategy` and how to override it. + +```typescript +import { createClient } from 'redis'; + +const client = createClient({ + socket: { + reconnectStrategy: (retries) => Math.min(retries * 50, 500) + } +}); +``` + ## TLS To enable TLS, set `socket.tls` to `true`. Below are some basic examples.