Skip to content

Commit 9795690

Browse files
committed
docs
1 parent 0c6bbc9 commit 9795690

File tree

4 files changed

+51
-20
lines changed

4 files changed

+51
-20
lines changed

docs/RESP.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
# RESP2 -> JS
1+
# RESP
2+
3+
## Type Mapping
4+
5+
## RESP2 -> JS
26

37
- Integer (`:`) => `number`
48
- Simple String (`+`) => `string | Buffer`
59
- Blob String (`$`) => `string | Buffer`
610
- Simple Error (`-`) => `ErrorReply`
711
- Array (`*`) => `Array`
812

9-
# RESP3 -> JS
13+
## RESP3 -> JS
1014

1115
- Null (`_`) => `null`
1216
- Boolean (`#`) => `boolean`

docs/command-options.md

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
> :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).
44
5-
TODO: "proxy client" concept
5+
TODO
66

77
## Type Mapping
88

9-
TODO [RESP](./RESP.md)
10-
11-
`withTypeMapping`
9+
Some RESP types can be mapped to more than one JavaScript type. For example, "Blob String" can be mapped to `string` or `Buffer`.
10+
You can override the default type mapping using the `withTypeMapping` function:
1211

1312
```javascript
1413
await client.get('key'); // `string | null`
@@ -20,18 +19,52 @@ const proxyClient = client.withTypeMapping({
2019
await proxyClient.get('key'); // `Buffer | null`
2120
```
2221

22+
See [RESP](./RESP.md) for a full list of types.
23+
2324
## Abort Signal
2425

25-
TODO
26+
Commands can be aborted using the [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) API:
27+
28+
```javascript
2629

27-
`withAbortSignal`
30+
const controller = new AbortController();
31+
controller.abort();
32+
33+
try {
34+
await client.withAbortSignal(controller.signal).get('key');
35+
} catch (err) {
36+
// AbortError
37+
}
38+
```
39+
40+
> NOTE: Commands that are already written to the socket cannot be aborted.
2841
2942
## ASAP
3043

31-
TODO
44+
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.
3245

33-
`asap`
46+
```javascript
47+
const asapClient = client.asap();
48+
49+
client.on('connect', () => {
50+
asapClient.clientSetName('my-name')
51+
.catch(err => console.error('CLIENT SETNAME error', err));
52+
});
53+
```
3454

3555
## `withCommandOptions`
3656

37-
TODO
57+
The `withCommandOptions` overrides all of the command options, without reusing any existing ones:
58+
59+
```javascript
60+
const bufferClient = client.withTypeMapping({
61+
[TYPES.BLOB_STRING]: Buffer
62+
});
63+
64+
await bufferClient.get('key'); // `Buffer | null`
65+
66+
// reset all command options
67+
const defaultClient = client.withCommandOptions({});
68+
69+
await defaultClient.get('key'); // `string | null`
70+
```

docs/pub-sub.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ await client.pSubscribe('channe*', listener);
3939
await client.sSubscribe('channel', listener);
4040
```
4141

42+
> NOTE: Subscribing to the same channel more than once will create multiple listeners which will each be called when a message is recieved.
43+
4244
## Publishing
4345

4446
```javascript

docs/v4-to-v5.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,7 @@ const proxyClient = client.withCommandOptions({
3030
await proxyClient.get('key'); // `Buffer | null`
3131
```
3232

33-
`withCommandOptions` can be used to override all of the command options, without reusing any existing ones.
34-
35-
To override just a specific option, use the following functions:
36-
- `withTypeMapping` - override `typeMapping` only.
37-
- `withAbortSignal` - override `abortSignal` only.
38-
- `asap` - override `asap` to `true`.
39-
- `isolated` - override `isolated` to `true`.
40-
41-
[TODO](./command-options.md)
33+
for more information, see the [Command Options guide](./command-options.md).
4234

4335
## Quit VS Disconnect
4436

0 commit comments

Comments
 (0)