Skip to content

Commit 2aab6eb

Browse files
committed
add 'sharded-channel-moved' event to docs, improve the events section in the main README (fix #2302)
1 parent b82fcf5 commit 2aab6eb

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,18 @@ Check out the [Clustering Guide](./docs/clustering.md) when using Node Redis to
363363

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

366-
| Event name | Scenes | Arguments to be passed to the listener |
367-
|----------------|-------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|
368-
| `connect` | The client is initiating a connection to the server. | _No argument_ |
369-
| `ready` | The client successfully initiated the connection to the server. | _No argument_ |
370-
| `end` | The client disconnected the connection to the server via `.quit()` or `.disconnect()`. | _No argument_ |
371-
| `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]` |
372-
| `reconnecting` | The client is trying to reconnect to the server. | _No argument_ |
373-
374-
The client will not emit [any other events](./docs/v3-to-v4.md#all-the-removed-events) beyond those listed above.
366+
| Name | When | Listener arguments |
367+
|-------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
368+
| `connect` | Initiating a connection to the server | *No arguments* |
369+
| `ready` | Client is ready to use | *No arguments* |
370+
| `end` | Connection has been closed (via `.quit()` or `.disconnect()`) | *No arguments* |
371+
| `error` | An error has occurred—usually a network issue such as "Socket closed unexpectedly" | `(error: Error)` |
372+
| `reconnecting` | Client is trying to reconnect to the server | *No arguments* |
373+
| `sharded-channel-moved` | The ["cluster slot"](https://redis.io/docs/reference/cluster-spec/#key-distribution-model) of a subscribed [sharded PubSub](https://redis.io/docs/manual/pubsub/#sharded-pubsub) channel has been moved | `(channel: string, listeners: { buffers: Set<Listener<Buffer>>, strings: Set<Listener<string>> })` |
374+
375+
> :warning: You **MUST** listen to `error` events. If a client doesn't have at least one `error` listener registered and an `error` occurs, that error will be thrown and the Node.js process will exit. See the [`EventEmitter` docs](https://nodejs.org/api/events.html#events_error_events) for more details.
376+
377+
> The client will not emit [any other events](./docs/v3-to-v4.md#all-the-removed-events) beyond those listed above.
375378
376379
## Supported Redis versions
377380

packages/client/lib/client/commands-queue.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface CommandWaitingForReply {
3030

3131
const PONG = Buffer.from('pong');
3232

33-
type OnServerSUnsubscribe = (channel: string, listeners?: ChannelListeners) => void;
33+
type OnShardedChannelMoved = (channel: string, listeners?: ChannelListeners) => void;
3434

3535
export default class RedisCommandsQueue {
3636
static #flushQueue<T extends CommandWaitingForReply>(queue: LinkedList<T>, err: Error): void {
@@ -42,7 +42,7 @@ export default class RedisCommandsQueue {
4242
readonly #maxLength: number | null | undefined;
4343
readonly #waitingToBeSent = new LinkedList<CommandWaitingToBeSent>();
4444
readonly #waitingForReply = new LinkedList<CommandWaitingForReply>();
45-
readonly #onServerSUnsubscribe: OnServerSUnsubscribe;
45+
readonly #onShardedChannelMoved: OnShardedChannelMoved;
4646

4747
readonly #pubSub = new PubSub();
4848

@@ -60,7 +60,7 @@ export default class RedisCommandsQueue {
6060
const isShardedUnsubscribe = PubSub.isShardedUnsubscribe(reply as Array<Buffer>);
6161
if (isShardedUnsubscribe && !this.#waitingForReply.length) {
6262
const channel = (reply[1] as Buffer).toString();
63-
this.#onServerSUnsubscribe(
63+
this.#onShardedChannelMoved(
6464
channel,
6565
this.#pubSub.removeShardedListeners(channel)
6666
);
@@ -94,10 +94,10 @@ export default class RedisCommandsQueue {
9494

9595
constructor(
9696
maxLength: number | null | undefined,
97-
onServerSUnsubscribe: OnServerSUnsubscribe
97+
onShardedChannelMoved: OnShardedChannelMoved
9898
) {
9999
this.#maxLength = maxLength;
100-
this.#onServerSUnsubscribe = onServerSUnsubscribe;
100+
this.#onShardedChannelMoved = onShardedChannelMoved;
101101
}
102102

103103
addCommand<T = RedisCommandRawReply>(args: RedisCommandArguments, options?: QueueCommandOptions): Promise<T> {

0 commit comments

Comments
 (0)