Skip to content

Commit 9257e23

Browse files
AnnAngelaleibalesimonprickett
authored
Update v3-to-v4.md (#1737)
* Update v3-to-v4.md * Update v3-to-v4.md * Update v3-to-v4.md * Update docs/v3-to-v4.md Co-authored-by: Simon Prickett <[email protected]> * Update docs/v3-to-v4.md Co-authored-by: Simon Prickett <[email protected]> * Update docs/v3-to-v4.md Co-authored-by: Simon Prickett <[email protected]> * Update docs/v3-to-v4.md Co-authored-by: Simon Prickett <[email protected]> * Update docs/v3-to-v4.md Co-authored-by: Simon Prickett <[email protected]> * Update docs/v3-to-v4.md Co-authored-by: Simon Prickett <[email protected]> Co-authored-by: Leibale Eidelman <[email protected]> Co-authored-by: Simon Prickett <[email protected]>
1 parent f648f37 commit 9257e23

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

docs/v3-to-v4.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,54 @@
22

33
Version 4 of Node Redis is a major refactor. While we have tried to maintain backwards compatibility where possible, several interfaces have changed. Read this guide to understand the differences and how to implement version 4 in your application.
44

5-
## Breaking Changes
5+
## All of the Breaking Changes
66

77
See the [Change Log](../packages/client/CHANGELOG.md).
88

9-
## Promises
9+
### Promises
1010

1111
Node Redis now uses native [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) by default for all functions.
1212

13+
### `createClient`
14+
15+
The configuration object passed to `createClient` has changed significantly with this release. See the [client configuration guide](./client-configuration.md) for details.
16+
17+
### No Auto Connect
18+
19+
In V4, the client does not automatically connect to the server, you need to run `.connect()` before any command, or you will receive error `ClientClosedError: The client is closed`.
20+
21+
```typescript
22+
import { createClient } from 'redis';
23+
24+
const client = createClient();
25+
26+
await client.connect();
27+
28+
await client.ping();
29+
```
30+
31+
### No `message` event
32+
33+
In V4, you don't need to add listener to the `message` and `message_buffer` events, you can get the message directly in `subscribe`-like commands.
34+
35+
The second argument of these commands is a callback, which will be triggered every time there is a message published to the channel.
36+
37+
The third argument to these commands is a boolean to set `bufferMode` (default `false`). If it's set to `true` you will receive a buffer instead of a string.
38+
39+
The `subscribe`-like commands return a promise. If the server returns `ok` the promise will be fulfilled, otherwise the promise will be rejected.
40+
41+
```typescript
42+
import { createClient } from 'redis';
43+
44+
const subscriber = createClient();
45+
46+
await subscriber.connect();
47+
48+
await subscriber.subscribe('channel_name', (message, channelName) => {
49+
console.info(message, channelName);
50+
});
51+
```
52+
1353
## Legacy Mode
1454

1555
Use legacy mode to preserve the backwards compatibility of commands while still getting access to the updated experience:
@@ -29,7 +69,3 @@ await client.v4.set('key', 'value', {
2969
NX: true
3070
});
3171
```
32-
33-
## `createClient`
34-
35-
The configuration object passed to `createClient` has changed significantly with this release. See the [client configuration guide](./client-configuration.md) for details.

0 commit comments

Comments
 (0)