From 0865d2277725b64c18dad05e8a6231c547a8cbdb Mon Sep 17 00:00:00 2001 From: leibale Date: Mon, 13 Dec 2021 10:17:12 -0500 Subject: [PATCH] fix #1774 #1767 - update docs Co-authored-by: Chayim --- docs/FAQ.md | 12 +++++++++++ docs/client-configuration.md | 40 +++++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index cfdb2ecaf4..5d65ff7ee0 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -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). 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; +``` \ No newline at end of file diff --git a/docs/client-configuration.md b/docs/client-configuration.md index 4ea94fcab1..32ecbd9f0e 100644 --- a/docs/client-configuration.md +++ b/docs/client-configuration.md @@ -11,7 +11,7 @@ | 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.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 | | username | | ACL username ([see ACL guide](https://redis.io/topics/acl)) | | password | | ACL password or the old "--requirepass" password | @@ -26,9 +26,39 @@ ## 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. -- Should return `number | Error`: - - `number`: the time in milliseconds to wait before trying to reconnect again. - - `Error`: close the client and flush the commands queue. +- Returns `number | Error`: + - `number`: the wait time in milliseconds prior attempting to reconnect. + - `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: '...' + } +}); +``` \ No newline at end of file