diff --git a/docs/RESP.md b/docs/RESP.md index 5d428497c9..f31c395f8c 100644 --- a/docs/RESP.md +++ b/docs/RESP.md @@ -1,4 +1,8 @@ -# RESP2 -> JS +# RESP + +## Type Mapping + +## RESP2 -> JS - Integer (`:`) => `number` - Simple String (`+`) => `string | Buffer` @@ -6,7 +10,7 @@ - Simple Error (`-`) => `ErrorReply` - Array (`*`) => `Array` -# RESP3 -> JS +## RESP3 -> JS - Null (`_`) => `null` - Boolean (`#`) => `boolean` diff --git a/docs/command-options.md b/docs/command-options.md index 0f2a27ec75..926db1a7be 100644 --- a/docs/command-options.md +++ b/docs/command-options.md @@ -2,13 +2,12 @@ > :warning: The command options API in v5 has breaking changes from the previous version. For more details, refer to the [v4-to-v5 guide](./v4-to-v5.md#command-options). -TODO: "proxy client" concept +TODO ## Type Mapping -TODO [RESP](./RESP.md) - -`withTypeMapping` +Some RESP types can be mapped to more than one JavaScript type. For example, "Blob String" can be mapped to `string` or `Buffer`. +You can override the default type mapping using the `withTypeMapping` function: ```javascript await client.get('key'); // `string | null` @@ -20,18 +19,52 @@ const proxyClient = client.withTypeMapping({ await proxyClient.get('key'); // `Buffer | null` ``` +See [RESP](./RESP.md) for a full list of types. + ## Abort Signal -TODO +Commands can be aborted using the [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) API: -`withAbortSignal` +```javascript + +const controller = new AbortController(); +controller.abort(); + +try { + await client.withAbortSignal(controller.signal).get('key'); +} catch (err) { + // AbortError +} +``` + +> NOTE: Commands that are already written to the socket cannot be aborted. ## ASAP -TODO +Commands that are executed in the "asap" mode are added to the top of the queue. This is useful to ensure that commands are executed before other commands that are already in the queue. -`asap` +```javascript +const asapClient = client.asap(); + +client.on('connect', () => { + asapClient.clientSetName('my-name') + .catch(err => console.error('CLIENT SETNAME error', err)); +}); +``` ## `withCommandOptions` -TODO +The `withCommandOptions` overrides all of the command options, without reusing any existing ones: + +```javascript +const bufferClient = client.withTypeMapping({ + [TYPES.BLOB_STRING]: Buffer +}); + +await bufferClient.get('key'); // `Buffer | null` + +// reset all command options +const defaultClient = client.withCommandOptions({}); + +await defaultClient.get('key'); // `string | null` +``` diff --git a/docs/pub-sub.md b/docs/pub-sub.md index 4b0e138d8a..6d210e2fe1 100644 --- a/docs/pub-sub.md +++ b/docs/pub-sub.md @@ -39,6 +39,8 @@ await client.pSubscribe('channe*', listener); await client.sSubscribe('channel', listener); ``` +> NOTE: Subscribing to the same channel more than once will create multiple listeners which will each be called when a message is recieved. + ## Publishing ```javascript diff --git a/docs/v4-to-v5.md b/docs/v4-to-v5.md index 6d24149ff7..911309d98b 100644 --- a/docs/v4-to-v5.md +++ b/docs/v4-to-v5.md @@ -30,15 +30,7 @@ const proxyClient = client.withCommandOptions({ await proxyClient.get('key'); // `Buffer | null` ``` -`withCommandOptions` can be used to override all of the command options, without reusing any existing ones. - -To override just a specific option, use the following functions: -- `withTypeMapping` - override `typeMapping` only. -- `withAbortSignal` - override `abortSignal` only. -- `asap` - override `asap` to `true`. -- `isolated` - override `isolated` to `true`. - -[TODO](./command-options.md) +for more information, see the [Command Options guide](./command-options.md). ## Quit VS Disconnect