Skip to content

Commit 3ff0ffa

Browse files
authored
Update v3-to-v4.md
1 parent 633cae3 commit 3ff0ffa

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

docs/v3-to-v4.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ The configuration object passed to `createClient` has changed significantly with
1616

1717
### No Auto Connect
1818

19-
In V4, the client will not be auto connected to the server, you need to run `.connect()` before any command, or you will receive error `Uncaught ClientClosedError: The client is closed`.
19+
In V4, the client will not be auto connected to the server, you need to run `.connect()` before any command, or you will receive error `ClientClosedError: The client is closed`.
2020

21-
```javascript
22-
const redis = require("redis");
23-
const client = redis.createClient();
21+
```typescript
22+
import { createClient } from 'redis';
2423

25-
client.connect().then(() => { // the connect method returns promise!
26-
return client.select();
27-
});
24+
const client = createClient();
25+
26+
await client.connect();
27+
28+
await client.ping();
2829
```
2930

3031
### No `message` event
@@ -37,18 +38,15 @@ The third agrument of commands is a boolean to set `bufferMode` (default `false`
3738

3839
The `subscribe`-like commands return a promise, if the server returns `ok` the promise will be fulfilled, otherwise the promise will be rejected.
3940

40-
```javascript
41-
const redis = require("redis");
42-
const subscriber = redis.createClient();
43-
44-
subscriber.connect().then(() => { // the connect method returns promise!
45-
subscriber.subscribe("channel_name", (message, channelName) => {
46-
console.info(message, channelName);
47-
}).then(() => {
48-
// ok
49-
}).catch((reason) => {
50-
// failed with `reason`
51-
});
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);
5250
});
5351
```
5452

0 commit comments

Comments
 (0)