You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
docs
This commit is contained in:
@@ -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`
|
||||
```
|
||||
|
Reference in New Issue
Block a user