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