You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
This commit is contained in:
@@ -3,7 +3,7 @@ import testUtils, { GLOBAL, waitTillBeenCalled } from '../test-utils';
|
||||
import RedisClient, { RedisClientType } from '.';
|
||||
import { RedisClientMultiCommandType } from './multi-command';
|
||||
import { RedisCommandArguments, RedisCommandRawReply, RedisModules, RedisFunctions, RedisScripts } from '../commands';
|
||||
import { AbortError, ClientClosedError, ConnectionTimeoutError, DisconnectsClientError, SocketClosedUnexpectedlyError, WatchError } from '../errors';
|
||||
import { AbortError, ClientClosedError, ClientOfflineError, ConnectionTimeoutError, DisconnectsClientError, SocketClosedUnexpectedlyError, WatchError } from '../errors';
|
||||
import { defineScript } from '../lua-script';
|
||||
import { spy } from 'sinon';
|
||||
import { once } from 'events';
|
||||
@@ -874,4 +874,20 @@ describe('Client', () => {
|
||||
pingInterval: 1
|
||||
}
|
||||
});
|
||||
|
||||
testUtils.testWithClient('should reject commands in connect phase when `disableOfflineQueue`', async client => {
|
||||
const connectPromise = client.connect();
|
||||
await assert.rejects(
|
||||
client.ping(),
|
||||
ClientOfflineError
|
||||
);
|
||||
await connectPromise;
|
||||
await client.disconnect();
|
||||
}, {
|
||||
...GLOBAL.SERVERS.OPEN,
|
||||
clientOptions: {
|
||||
disableOfflineQueue: true
|
||||
},
|
||||
disableClientSetup: true
|
||||
});
|
||||
});
|
||||
|
@@ -11,7 +11,7 @@ import { ScanCommandOptions } from '../commands/SCAN';
|
||||
import { HScanTuple } from '../commands/HSCAN';
|
||||
import { attachCommands, attachExtensions, fCallArguments, transformCommandArguments, transformCommandReply, transformLegacyCommandArguments } from '../commander';
|
||||
import { Pool, Options as PoolOptions, createPool } from 'generic-pool';
|
||||
import { ClientClosedError, DisconnectsClientError } from '../errors';
|
||||
import { ClientClosedError, ClientOfflineError, DisconnectsClientError } from '../errors';
|
||||
import { URL } from 'url';
|
||||
import { TcpSocketConnectOpts } from 'net';
|
||||
|
||||
@@ -405,15 +405,15 @@ export default class RedisClient<
|
||||
): Promise<T> {
|
||||
if (!this.#socket.isOpen) {
|
||||
return Promise.reject(new ClientClosedError());
|
||||
}
|
||||
|
||||
if (options?.isolated) {
|
||||
} else if (options?.isolated) {
|
||||
return this.executeIsolated(isolatedClient =>
|
||||
isolatedClient.sendCommand(args, {
|
||||
...options,
|
||||
isolated: false
|
||||
})
|
||||
);
|
||||
} else if (!this.#socket.isReady && this.#options?.disableOfflineQueue) {
|
||||
return Promise.reject(new ClientOfflineError());
|
||||
}
|
||||
|
||||
const promise = this.#queue.addCommand<T>(args, options);
|
||||
|
@@ -22,6 +22,12 @@ export class ClientClosedError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export class ClientOfflineError extends Error {
|
||||
constructor() {
|
||||
super('The client is offline');
|
||||
}
|
||||
}
|
||||
|
||||
export class DisconnectsClientError extends Error {
|
||||
constructor() {
|
||||
super('Disconnects client');
|
||||
|
Reference in New Issue
Block a user