From 6dd15d96aa0534e37a6695d4a217fa82b1ac08bb Mon Sep 17 00:00:00 2001 From: Leibale Eidelman Date: Mon, 14 Feb 2022 15:23:18 -0500 Subject: [PATCH] ref #1888 - add disableOfflineQueue (#1900) * ref #1888 - add disableOfflineQueue * fix flushQueuesOnError * update docs Co-authored-by: Guy Royse Co-authored-by: Guy Royse --- docs/FAQ.md | 4 +++- docs/client-configuration.md | 1 + packages/client/lib/client/index.ts | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 5d65ff7ee0..3babbb9d84 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -4,7 +4,9 @@ Nobody has *actually* asked these questions. But, we needed somewhere to put all ## What happens when the network goes down? -When a socket closed unexpectedly, all the commands that were already sent will reject as they might have been executed on the server. The rest will remain queued in memory until a new socket is established. If the client is closed—either by returning an error from [`reconnectStrategy`](./client-configuration.md#reconnect-strategy) or by manually calling `.disconnect()`—they will be rejected. +When a socket closes unexpectedly, all the commands that were already sent will reject as they might have been executed on the server. The rest will remain queued in memory until a new socket is established. If the client is closed—either by returning an error from [`reconnectStrategy`](./client-configuration.md#reconnect-strategy) or by manually calling `.disconnect()`—they will be rejected. + +If don't want to queue commands in memory until a new socket is established, set the `disableOfflineQueue` option to `true` in the [client configuration](./client-configuration.md). This will result in those commands being rejected. ## How are commands batched? diff --git a/docs/client-configuration.md b/docs/client-configuration.md index 0600d8e576..092f3d8eb8 100644 --- a/docs/client-configuration.md +++ b/docs/client-configuration.md @@ -20,6 +20,7 @@ | modules | | Object defining which [Redis Modules](../README.md#packages) to include | | scripts | | Object defining Lua Scripts to use with this client (see [Lua Scripts](../README.md#lua-scripts)) | | commandsQueueMaxLength | | Maximum length of the client's internal command queue | +| disableOfflineQueue | `false` | Disables offline queuing, see the [FAQ](./FAQ.md#what-happens-when-the-network-goes-down) for details | | readonly | `false` | Connect in [`READONLY`](https://redis.io/commands/readonly) mode | | legacyMode | `false` | Maintain some backwards compatibility (see the [Migration Guide](./v3-to-v4.md)) | | isolationPoolOptions | | See the [Isolated Execution Guide](./isolated-execution.md) | diff --git a/packages/client/lib/client/index.ts b/packages/client/lib/client/index.ts index 2ce93773e9..da0b95bd42 100644 --- a/packages/client/lib/client/index.ts +++ b/packages/client/lib/client/index.ts @@ -26,6 +26,7 @@ export interface RedisClientOptions< name?: string; database?: number; commandsQueueMaxLength?: number; + disableOfflineQueue?: boolean; readonly?: boolean; legacyMode?: boolean; isolationPoolOptions?: PoolOptions; @@ -274,7 +275,7 @@ export default class RedisClient .on('data', data => this.#queue.parseResponse(data)) .on('error', err => { this.emit('error', err); - if (this.#socket.isOpen) { + if (this.#socket.isOpen && !this.#options?.disableOfflineQueue) { this.#queue.flushWaitingForReply(err); } else { this.#queue.flushAll(err);