Skip to content

Commit

Permalink
Add the list of removed events to migration guide (redis#1761)
Browse files Browse the repository at this point in the history
* Update v3-to-v4.md

* Update README.md

* Correct the wrong description

* 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: Simon Prickett <[email protected]>
  • Loading branch information
AnnAngela and simonprickett authored Jan 13, 2022
1 parent e3c314e commit 9516b88
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,15 @@ Check out the [Clustering Guide](./docs/clustering.md) when using Node Redis to

The Node Redis client class is an Nodejs EventEmitter and it emits an event each time the network status changes:

| Event name | Scenes | Parameters |
|--------------|-------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| connect | The client is initiating a connection to the server. | _undefined_ |
| ready | The client successfully initiated the connection to the server. | _undefined_ |
| end | The client disconnected the connection to the server via `.quit()` or `.disconnect()`. | _undefined_ |
| error | When a network error has occurred, such as unable to connect to the server or the connection closed unexpectedly. | The error object, such as `SocketClosedUnexpectedlyError: Socket closed unexpectedly` or `Error: connect ECONNREFUSED [IP]:[PORT]` |
| reconnecting | The client is trying to reconnect to the server. | _undefined_ |

The client will not emit any other events beyond those listed above.
| Event name | Scenes | Arguments to be passed to the listener |
|----------------|-------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|
| `connect` | The client is initiating a connection to the server. | _No argument_ |
| `ready` | The client successfully initiated the connection to the server. | _No argument_ |
| `end` | The client disconnected the connection to the server via `.quit()` or `.disconnect()`. | _No argument_ |
| `error` | When a network error has occurred, such as unable to connect to the server or the connection closed unexpectedly. | 1 argument: The error object, such as `SocketClosedUnexpectedlyError: Socket closed unexpectedly` or `Error: connect ECONNREFUSED [IP]:[PORT]` |
| `reconnecting` | The client is trying to reconnect to the server. | _No argument_ |

The client will not emit [any other events](./docs/v3-to-v4.md#all-the-removed-events) beyond those listed above.

## Supported Redis versions

Expand Down
22 changes: 19 additions & 3 deletions docs/v3-to-v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,31 @@ await client.connect();
await client.ping();
```

### No `message` event
### All the removed events

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 following events that existed in V3 were removed in V4:

1. `warning`
2. `subscribe`
3. `psubscribe`
4. `unsubscribe`
5. `message`
6. `message_buffer`
7. `messageBuffer`
8. `pmessage`
9. `pmessage_buffer`
10. `pmessageBuffer`
11. `monitor`

#### No `message`-like event

In V4, you don't need to add a listener to the `message`-like events (items 5 to 10 of the above list), you can get the message directly in `subscribe`-like commands.

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 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 command is executed successfully the promise will be fulfilled, otherwise the promise will be rejected.

```typescript
import { createClient } from 'redis';
Expand Down

0 comments on commit 9516b88

Please sign in to comment.