1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00
This commit is contained in:
Leibale
2023-06-08 07:17:42 -04:00
parent 0c6bbc99ef
commit 9795690364
4 changed files with 51 additions and 20 deletions

View File

@@ -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`

View File

@@ -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`
```

View File

@@ -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

View File

@@ -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