|
1 | 1 | # RESP3 Support
|
2 | 2 |
|
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: |
4 | 6 |
|
5 | 7 | ```javascript
|
| 8 | +import { createClient } from 'redis'; |
| 9 | + |
6 | 10 | const client = createClient({
|
7 | 11 | RESP: 3
|
8 | 12 | });
|
9 | 13 | ```
|
10 | 14 |
|
| 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 | + |
11 | 19 | ```javascript
|
12 |
| -// by default |
| 20 | +import { createClient, RESP_TYPES } from 'redis'; |
| 21 | + |
| 22 | +// By default |
13 | 23 | await client.hGetAll('key'); // Record<string, string>
|
14 | 24 |
|
| 25 | +// Use Map instead of plain object |
15 | 26 | await client.withTypeMapping({
|
16 |
| - [TYPES.MAP]: Map |
| 27 | + [RESP_TYPES.MAP]: Map |
17 | 28 | }).hGetAll('key'); // Map<string, string>
|
18 | 29 |
|
| 30 | +// Use both Map and Buffer |
19 | 31 | await client.withTypeMapping({
|
20 |
| - [TYPES.MAP]: Map, |
21 |
| - [TYPES.BLOB_STRING]: Buffer |
| 32 | + [RESP_TYPES.MAP]: Map, |
| 33 | + [RESP_TYPES.BLOB_STRING]: Buffer |
22 | 34 | }).hGetAll('key'); // Map<string, Buffer>
|
23 | 35 | ```
|
24 | 36 |
|
| 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 | + |
25 | 78 | # Sentinel Support
|
26 | 79 |
|
27 |
| -[TODO](./sentinel.md) |
| 80 | +[Sentinel](./sentinel.md) |
28 | 81 |
|
29 | 82 | # `multi.exec<'typed'>` / `multi.execTyped`
|
30 | 83 |
|
|
0 commit comments