Skip to content

Commit 37f928e

Browse files
committed
more v5 docs updates
1 parent 53e3575 commit 37f928e

File tree

4 files changed

+72
-14
lines changed

4 files changed

+72
-14
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,13 @@ await client.hVals("key"); // ['value1', 'value2']
124124
`Buffer`s are supported as well:
125125

126126
```typescript
127+
const client = createClient().withTypeMapping({
128+
[RESP_TYPES.BLOB_STRING]: Buffer
129+
});
130+
127131
await client.hSet("key", "field", Buffer.from("value")); // 'OK'
128-
await client.hGetAll(commandOptions({ returnBuffers: true }), "key"); // { field: <Buffer 76 61 6c 75 65> }
132+
await client.hGet("key", "field"); // { field: <Buffer 76 61 6c 75 65> }
133+
129134
```
130135

131136
### Unsupported Redis Commands

docs/RESP.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ By default, each type is mapped to the first option in the lists below. To chang
2323
- Double (`,`) => `number | string`
2424
- Simple String (`+`) => `string | Buffer`
2525
- Blob String (`$`) => `string | Buffer`
26-
- Verbatim String (`=`) => `string | Buffer | VerbatimString` (TODO: `VerbatimString` typedoc link)
26+
- Verbatim String (`=`) => `string | Buffer | VerbatimString`
2727
- Simple Error (`-`) => `ErrorReply`
2828
- Blob Error (`!`) => `ErrorReply`
2929
- Array (`*`) => `Array`

docs/v4-to-v5.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,12 @@ In v5, any unwritten commands (in the same pipeline) will be discarded.
225225
### Time Series
226226

227227
- `TS.ADD`: `boolean` -> `number` [^boolean-to-number]
228-
- `TS.[M][REV]RANGE`: `enum TimeSeriesBucketTimestamp` -> `const TIME_SERIES_BUCKET_TIMESTAMP` [^enum-to-constants], `enum TimeSeriesReducers` -> `const TIME_SERIES_REDUCERS` [^enum-to-constants], the `ALIGN` argument has been moved into `AGGREGRATION`
228+
- `TS.[M][REV]RANGE`: the `ALIGN` argument has been moved into `AGGREGATION`
229229
- `TS.SYNUPDATE`: `Array<string | Array<string>>` -> `Record<string, Array<string>>`
230-
- `TS.M[REV]RANGE[_WITHLABELS]`, `TS.MGET[_WITHLABELS]`: TODO
231-
232-
[^enum-to-constants]: TODO
230+
- `TimeSeriesDuplicatePolicies` -> `TIME_SERIES_DUPLICATE_POLICIES` [^enum-to-constants]
231+
- `TimeSeriesEncoding` -> `TIME_SERIES_ENCODING` [^enum-to-constants]
232+
- `TimeSeriesAggregationType` -> `TIME_SERIES_AGGREGATION_TYPE` [^enum-to-constants]
233+
- `TimeSeriesReducers` -> `TIME_SERIES_REDUCERS` [^enum-to-constants]
234+
- `TimeSeriesBucketTimestamp` -> `TIME_SERIES_BUCKET_TIMESTAMP` [^enum-to-constants]
233235

234236
[^map-keys]: To avoid unnecessary transformations and confusion, map keys will not be transformed to "js friendly" names (i.e. `number-of-keys` will not be renamed to `numberOfKeys`). See [here](https://github.com/redis/node-redis/discussions/2506).
235-
236-
[^future-proofing]: TODO

docs/v5.md

+59-6
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,83 @@
11
# RESP3 Support
22

3-
TODO
3+
Node Redis v5 adds support for [RESP3](https://github.com/redis/redis-specifications/blob/master/protocol/RESP3.md), the new Redis serialization protocol. RESP3 offers richer data types and improved type handling compared to RESP2.
4+
5+
To use RESP3, specify it when creating your client:
46

57
```javascript
8+
import { createClient } from 'redis';
9+
610
const client = createClient({
711
RESP: 3
812
});
913
```
1014

15+
## Type Mapping
16+
17+
With RESP3, you can leverage the protocol's richer type system. You can customize how different Redis types are represented in JavaScript using type mapping:
18+
1119
```javascript
12-
// by default
20+
import { createClient, RESP_TYPES } from 'redis';
21+
22+
// By default
1323
await client.hGetAll('key'); // Record<string, string>
1424

25+
// Use Map instead of plain object
1526
await client.withTypeMapping({
16-
[TYPES.MAP]: Map
27+
[RESP_TYPES.MAP]: Map
1728
}).hGetAll('key'); // Map<string, string>
1829

30+
// Use both Map and Buffer
1931
await client.withTypeMapping({
20-
[TYPES.MAP]: Map,
21-
[TYPES.BLOB_STRING]: Buffer
32+
[RESP_TYPES.MAP]: Map,
33+
[RESP_TYPES.BLOB_STRING]: Buffer
2234
}).hGetAll('key'); // Map<string, Buffer>
2335
```
2436

37+
This replaces the previous approach of using `commandOptions({ returnBuffers: true })` in v4.
38+
39+
## PubSub in RESP3
40+
41+
RESP3 uses a different mechanism for handling Pub/Sub messages. Instead of modifying the `onReply` handler as in RESP2, RESP3 provides a dedicated `onPush` handler. When using RESP3, the client automatically uses this more efficient push notification system.
42+
43+
## Known Limitations
44+
45+
### Unstable Module Commands
46+
47+
Some Redis module commands have unstable RESP3 transformations. These commands will throw an error when used with RESP3 unless you explicitly opt in to using them by setting `unstableResp3: true` in your client configuration:
48+
49+
```javascript
50+
const client = createClient({
51+
RESP: 3,
52+
unstableResp3: true
53+
});
54+
```
55+
56+
The following commands have unstable RESP3 implementations:
57+
58+
1. **Stream Commands**:
59+
- `XREAD` and `XREADGROUP` - The response format differs between RESP2 and RESP3
60+
61+
2. **Search Commands (RediSearch)**:
62+
- `FT.AGGREGATE`
63+
- `FT.AGGREGATE_WITHCURSOR`
64+
- `FT.CURSOR_READ`
65+
- `FT.INFO`
66+
- `FT.PROFILE_AGGREGATE`
67+
- `FT.PROFILE_SEARCH`
68+
- `FT.SEARCH`
69+
- `FT.SEARCH_NOCONTENT`
70+
- `FT.SPELLCHECK`
71+
72+
3. **Time Series Commands**:
73+
- `TS.INFO`
74+
- `TS.INFO_DEBUG`
75+
76+
If you need to use these commands with RESP3, be aware that the response format might change in future versions.
77+
2578
# Sentinel Support
2679

27-
[TODO](./sentinel.md)
80+
[Sentinel](./sentinel.md)
2881

2982
# `multi.exec<'typed'>` / `multi.execTyped`
3083

0 commit comments

Comments
 (0)