Skip to content

Commit 6dd15d9

Browse files
leibaleguyroyse
andauthored
ref #1888 - add disableOfflineQueue (#1900)
* ref #1888 - add disableOfflineQueue * fix flushQueuesOnError * update docs Co-authored-by: Guy Royse <[email protected]> Co-authored-by: Guy Royse <[email protected]>
1 parent 9e904eb commit 6dd15d9

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

docs/FAQ.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Nobody has *actually* asked these questions. But, we needed somewhere to put all
44

55
## What happens when the network goes down?
66

7-
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.
7+
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.
8+
9+
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.
810

911
## How are commands batched?
1012

docs/client-configuration.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
| modules | | Object defining which [Redis Modules](../README.md#packages) to include |
2121
| scripts | | Object defining Lua Scripts to use with this client (see [Lua Scripts](../README.md#lua-scripts)) |
2222
| commandsQueueMaxLength | | Maximum length of the client's internal command queue |
23+
| disableOfflineQueue | `false` | Disables offline queuing, see the [FAQ](./FAQ.md#what-happens-when-the-network-goes-down) for details |
2324
| readonly | `false` | Connect in [`READONLY`](https://redis.io/commands/readonly) mode |
2425
| legacyMode | `false` | Maintain some backwards compatibility (see the [Migration Guide](./v3-to-v4.md)) |
2526
| isolationPoolOptions | | See the [Isolated Execution Guide](./isolated-execution.md) |

packages/client/lib/client/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface RedisClientOptions<
2626
name?: string;
2727
database?: number;
2828
commandsQueueMaxLength?: number;
29+
disableOfflineQueue?: boolean;
2930
readonly?: boolean;
3031
legacyMode?: boolean;
3132
isolationPoolOptions?: PoolOptions;
@@ -274,7 +275,7 @@ export default class RedisClient<M extends RedisModules, S extends RedisScripts>
274275
.on('data', data => this.#queue.parseResponse(data))
275276
.on('error', err => {
276277
this.emit('error', err);
277-
if (this.#socket.isOpen) {
278+
if (this.#socket.isOpen && !this.#options?.disableOfflineQueue) {
278279
this.#queue.flushWaitingForReply(err);
279280
} else {
280281
this.#queue.flushAll(err);

0 commit comments

Comments
 (0)