From 71354bdebceb66c2f8d0ec95718e65d26c90e448 Mon Sep 17 00:00:00 2001 From: AnnAngela Date: Sat, 27 Nov 2021 09:44:07 +0800 Subject: [PATCH 1/9] Update v3-to-v4.md --- docs/v3-to-v4.md | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/docs/v3-to-v4.md b/docs/v3-to-v4.md index 90267d8245c..492bd2f55c5 100644 --- a/docs/v3-to-v4.md +++ b/docs/v3-to-v4.md @@ -2,14 +2,54 @@ 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. -## Breaking Changes +## All the Breaking Changes See the [Change Log](../packages/client/CHANGELOG.md). -## Promises +### Promises Node Redis now uses native [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) by default for all functions. +### `createClient` + +The configuration object passed to `createClient` has changed significantly with this release. See the [client configuration guide](./client-configuration.md) for details. + +### No Auto Connect + +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`. + +```javascript +const redis = require("redis"); +const client = redis.createClient(); + +client.connect().then(() => { // the connect method returns promise! + return client.select(); +}); +``` + +### No `message` event + +In V4, you don't need to add listener to `message` and `message_buffer` event, you can get the message directly in `subscribe`-like commands. + +The second agrument of commands is a callback, and will be triggered every time when there is a message published to the channel. + +The `subscribe`-like commands return a promise, if the server returns `ok` the promise will be fulfilled, otherwise the promise will be rejected. + +```javascript +const redis = require("redis"); +const subscriber = redis.createClient(); + +subscriber.connect().then(() => { // the connect method returns promise! + subscriber.subscribe("channel_name", (message, channelName) => { + console.info(message, channelName); + }/* if you want to receive buffer please set the third argument to `true` */).then(() => { + // ok + }).catch((reason) => { + // failed with `reason` + }); +}); +``` + ## Legacy Mode 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', { NX: true }); ``` - -## `createClient` - -The configuration object passed to `createClient` has changed significantly with this release. See the [client configuration guide](./client-configuration.md) for details. From 633cae356192830e009a96e85c83c805550285ed Mon Sep 17 00:00:00 2001 From: AnnAngela Date: Sat, 27 Nov 2021 09:48:40 +0800 Subject: [PATCH 2/9] Update v3-to-v4.md --- docs/v3-to-v4.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/v3-to-v4.md b/docs/v3-to-v4.md index 492bd2f55c5..061e9e9ff7e 100644 --- a/docs/v3-to-v4.md +++ b/docs/v3-to-v4.md @@ -33,6 +33,8 @@ In V4, you don't need to add listener to `message` and `message_buffer` event, y The second agrument of commands is a callback, and will be triggered every time when there is a message published to the channel. +The third agrument of commands is a boolean to set `bufferMode` (default `false`), if it's `true` you will receive buffer instead of string. + The `subscribe`-like commands return a promise, if the server returns `ok` the promise will be fulfilled, otherwise the promise will be rejected. ```javascript @@ -42,7 +44,7 @@ const subscriber = redis.createClient(); subscriber.connect().then(() => { // the connect method returns promise! subscriber.subscribe("channel_name", (message, channelName) => { console.info(message, channelName); - }/* if you want to receive buffer please set the third argument to `true` */).then(() => { + }).then(() => { // ok }).catch((reason) => { // failed with `reason` From 3ff0ffa8d39c78a932e131bef6c23630b67c9588 Mon Sep 17 00:00:00 2001 From: Leibale Eidelman Date: Fri, 26 Nov 2021 22:17:58 -0500 Subject: [PATCH 3/9] Update v3-to-v4.md --- docs/v3-to-v4.md | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/docs/v3-to-v4.md b/docs/v3-to-v4.md index 061e9e9ff7e..7f8ff58dc94 100644 --- a/docs/v3-to-v4.md +++ b/docs/v3-to-v4.md @@ -16,15 +16,16 @@ The configuration object passed to `createClient` has changed significantly with ### No Auto Connect -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`. +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`. -```javascript -const redis = require("redis"); -const client = redis.createClient(); +```typescript +import { createClient } from 'redis'; -client.connect().then(() => { // the connect method returns promise! - return client.select(); -}); +const client = createClient(); + +await client.connect(); + +await client.ping(); ``` ### No `message` event @@ -37,18 +38,15 @@ The third agrument of commands is a boolean to set `bufferMode` (default `false` The `subscribe`-like commands return a promise, if the server returns `ok` the promise will be fulfilled, otherwise the promise will be rejected. -```javascript -const redis = require("redis"); -const subscriber = redis.createClient(); - -subscriber.connect().then(() => { // the connect method returns promise! - subscriber.subscribe("channel_name", (message, channelName) => { - console.info(message, channelName); - }).then(() => { - // ok - }).catch((reason) => { - // failed with `reason` - }); +```typescript +import { createClient } from 'redis'; + +const subscriber = createClient(); + +await subscriber.connect(); + +await subscriber.subscribe('channel_name', (message, channelName) => { + console.info(message, channelName); }); ``` From bcd1d98ab0e29f98f9851bcfc5b9e5ad4a487cc9 Mon Sep 17 00:00:00 2001 From: AnnAngela Date: Mon, 29 Nov 2021 18:50:41 +0800 Subject: [PATCH 4/9] Update docs/v3-to-v4.md Co-authored-by: Simon Prickett --- docs/v3-to-v4.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v3-to-v4.md b/docs/v3-to-v4.md index 7f8ff58dc94..44ba5baaa36 100644 --- a/docs/v3-to-v4.md +++ b/docs/v3-to-v4.md @@ -2,7 +2,7 @@ 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. -## All the Breaking Changes +## All of the Breaking Changes See the [Change Log](../packages/client/CHANGELOG.md). From bcb6bc40881139ef084752699179d122fab8e838 Mon Sep 17 00:00:00 2001 From: AnnAngela Date: Mon, 29 Nov 2021 18:50:47 +0800 Subject: [PATCH 5/9] Update docs/v3-to-v4.md Co-authored-by: Simon Prickett --- docs/v3-to-v4.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v3-to-v4.md b/docs/v3-to-v4.md index 44ba5baaa36..6031a920e10 100644 --- a/docs/v3-to-v4.md +++ b/docs/v3-to-v4.md @@ -30,7 +30,7 @@ await client.ping(); ### No `message` event -In V4, you don't need to add listener to `message` and `message_buffer` event, you can get the message directly in `subscribe`-like commands. +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. The second agrument of commands is a callback, and will be triggered every time when there is a message published to the channel. From 36368918943e061a24fc2912e1eb1a7d015580cc Mon Sep 17 00:00:00 2001 From: AnnAngela Date: Mon, 29 Nov 2021 18:50:56 +0800 Subject: [PATCH 6/9] Update docs/v3-to-v4.md Co-authored-by: Simon Prickett --- docs/v3-to-v4.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v3-to-v4.md b/docs/v3-to-v4.md index 6031a920e10..d30964e266f 100644 --- a/docs/v3-to-v4.md +++ b/docs/v3-to-v4.md @@ -16,7 +16,7 @@ The configuration object passed to `createClient` has changed significantly with ### No Auto Connect -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`. +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`. ```typescript import { createClient } from 'redis'; From 8cbbe14546c5cac8471003b82194bf45b40a890a Mon Sep 17 00:00:00 2001 From: AnnAngela Date: Mon, 29 Nov 2021 18:51:11 +0800 Subject: [PATCH 7/9] Update docs/v3-to-v4.md Co-authored-by: Simon Prickett --- docs/v3-to-v4.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v3-to-v4.md b/docs/v3-to-v4.md index d30964e266f..b5922cc0024 100644 --- a/docs/v3-to-v4.md +++ b/docs/v3-to-v4.md @@ -32,7 +32,7 @@ await client.ping(); 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. -The second agrument of commands is a callback, and will be triggered every time when there is a message published to the channel. +The second argument of these commands is a callback, which will be triggered every time there is a message published to the channel. The third agrument of commands is a boolean to set `bufferMode` (default `false`), if it's `true` you will receive buffer instead of string. From 415692620ebb23937017d1deb995a535397fcd2c Mon Sep 17 00:00:00 2001 From: AnnAngela Date: Mon, 29 Nov 2021 18:51:34 +0800 Subject: [PATCH 8/9] Update docs/v3-to-v4.md Co-authored-by: Simon Prickett --- docs/v3-to-v4.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v3-to-v4.md b/docs/v3-to-v4.md index b5922cc0024..619e6546290 100644 --- a/docs/v3-to-v4.md +++ b/docs/v3-to-v4.md @@ -34,7 +34,7 @@ In V4, you don't need to add listener to the `message` and `message_buffer` even The second argument of these commands is a callback, which will be triggered every time there is a message published to the channel. -The third agrument of commands is a boolean to set `bufferMode` (default `false`), if it's `true` you will receive buffer instead of string. +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. The `subscribe`-like commands return a promise, if the server returns `ok` the promise will be fulfilled, otherwise the promise will be rejected. From 395fea105ad7d4679f4a3abfb7e4e88649119ca8 Mon Sep 17 00:00:00 2001 From: AnnAngela Date: Mon, 29 Nov 2021 18:51:47 +0800 Subject: [PATCH 9/9] Update docs/v3-to-v4.md Co-authored-by: Simon Prickett --- docs/v3-to-v4.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v3-to-v4.md b/docs/v3-to-v4.md index 619e6546290..3ef43444c8e 100644 --- a/docs/v3-to-v4.md +++ b/docs/v3-to-v4.md @@ -36,7 +36,7 @@ The second argument of these commands is a callback, which will be triggered eve 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. -The `subscribe`-like commands return a promise, if the server returns `ok` the promise will be fulfilled, otherwise the promise will be rejected. +The `subscribe`-like commands return a promise. If the server returns `ok` the promise will be fulfilled, otherwise the promise will be rejected. ```typescript import { createClient } from 'redis';