You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
Add 'Network error handling' section to documentation (#2250)
* Add 'Network error handling' section to documentation * Merge 'Network error handling' section with existing doc * typo * Update README.md * typos Co-authored-by: Samuel CHEMLA <samuel.chemla@orange.com> Co-authored-by: Leibale Eidelman <me@leibale.com>
This commit is contained in:
@@ -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.
|
||||
|
Reference in New Issue
Block a user