1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

fix #1774 #1767 - update docs

Co-authored-by: Chayim <chayim@users.noreply.github.com>
This commit is contained in:
leibale
2021-12-13 10:17:12 -05:00
parent 7110f23369
commit 0865d22777
2 changed files with 47 additions and 5 deletions

View File

@@ -11,3 +11,15 @@ When a socket closed unexpectedly, all the commands that were already sent will
Commands are pipelined using [`queueMicrotask`](https://nodejs.org/api/globals.html#globals_queuemicrotask_callback). Commands are pipelined using [`queueMicrotask`](https://nodejs.org/api/globals.html#globals_queuemicrotask_callback).
If `socket.write()` returns `false`—meaning that ["all or part of the data was queued in user memory"](https://nodejs.org/api/net.html#net_socket_write_data_encoding_callback:~:text=all%20or%20part%20of%20the%20data%20was%20queued%20in%20user%20memory)—the commands will stack in memory until the [`drain`](https://nodejs.org/api/net.html#net_event_drain) event is fired. If `socket.write()` returns `false`—meaning that ["all or part of the data was queued in user memory"](https://nodejs.org/api/net.html#net_socket_write_data_encoding_callback:~:text=all%20or%20part%20of%20the%20data%20was%20queued%20in%20user%20memory)—the commands will stack in memory until the [`drain`](https://nodejs.org/api/net.html#net_event_drain) event is fired.
## `RedisClientType`
Redis has support for [modules](https://redis.io/modules) and running [Lua scripts](../README.md#lua-scripts) within the Redis context. To take advantage of typing within these scenarios, `RedisClient` and `RedisCluster` should be used with [typeof](https://www.typescriptlang.org/docs/handbook/2/typeof-types.html), rather than the base types `RedisClientType` and `RedisClusterType`.
```typescript
import { createClient } from '@node-redis/client';
export const client = createClient();
export type RedisClientType = typeof client;
```

View File

@@ -11,7 +11,7 @@
| socket.connectTimeout | `5000` | The timeout for connecting to the Redis Server (in milliseconds) | | socket.connectTimeout | `5000` | The timeout for connecting to the Redis Server (in milliseconds) |
| socket.noDelay | `true` | Enable/disable the use of [`Nagle's algorithm`](https://nodejs.org/api/net.html#net_socket_setnodelay_nodelay) | | socket.noDelay | `true` | Enable/disable the use of [`Nagle's algorithm`](https://nodejs.org/api/net.html#net_socket_setnodelay_nodelay) |
| socket.keepAlive | `5000` | Enable/disable the [`keep-alive`](https://nodejs.org/api/net.html#net_socket_setkeepalive_enable_initialdelay) functionality | | socket.keepAlive | `5000` | Enable/disable the [`keep-alive`](https://nodejs.org/api/net.html#net_socket_setkeepalive_enable_initialdelay) functionality |
| socket.tls | | Set to `true` to enable [TLS Configuration](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback) | | socket.tls | | See explanation and examples [below](#TLS) |
| socket.reconnectStrategy | `retries => Math.min(retries * 50, 500)` | A function containing the [Reconnect Strategy](#reconnect-strategy) logic | | socket.reconnectStrategy | `retries => Math.min(retries * 50, 500)` | A function containing the [Reconnect Strategy](#reconnect-strategy) logic |
| username | | ACL username ([see ACL guide](https://redis.io/topics/acl)) | | username | | ACL username ([see ACL guide](https://redis.io/topics/acl)) |
| password | | ACL password or the old "--requirepass" password | | password | | ACL password or the old "--requirepass" password |
@@ -26,9 +26,39 @@
## Reconnect Strategy ## Reconnect Strategy
You can implement a custom reconnect strategy as a function that should: You can implement a custom reconnect strategy as a function:
- Receives the number of retries attempted so far. - Receives the number of retries attempted so far.
- Should return `number | Error`: - Returns `number | Error`:
- `number`: the time in milliseconds to wait before trying to reconnect again. - `number`: the wait time in milliseconds prior attempting to reconnect.
- `Error`: close the client and flush the commands queue. - `Error`: closes the client and flushes the internal command queues.
## TLS
When creating a client, set `socket.tls` to `true` to enable TLS. Below are some basic examples.
> For configuration options see [tls.connect](https://nodejs.org/api/tls.html#tlsconnectoptions-callback) and [tls.createSecureContext](https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions), as those are the underlying functions used by this library.
### Create a SSL client
```typescript
createClient({
socket: {
tls: true,
ca: '...',
cert: '...'
}
});
```
### Create a SSL client using a self-signed certificate
```typescript
createClient({
socket: {
tls: true,
rejectUnauthorized: true,
cert: '...'
}
});
```