1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-11 22:42:42 +03:00

add isOpen boolean getter on client, add maxLength option to command queue, add test for client.multi

This commit is contained in:
leibale
2021-05-13 18:42:59 -04:00
parent b472efc116
commit 966c94a078
5 changed files with 66 additions and 21 deletions

View File

@@ -45,6 +45,8 @@ export default class RedisCommandsQueue {
}
}
readonly #maxLength: number | null | undefined;
readonly #executor: CommandsQueueExecutor;
readonly #waitingToBeSent = new LinkedList<CommandWaitingToBeSent>();
@@ -58,18 +60,32 @@ export default class RedisCommandsQueue {
#chainInExecution: Symbol | undefined;
constructor(executor: CommandsQueueExecutor) {
constructor(maxLength: number | null | undefined, executor: CommandsQueueExecutor) {
this.#maxLength = maxLength;
this.#executor = executor;
}
#isQueueFull<T = void>(): Promise<T> | undefined {
if (!this.#maxLength) return;
return this.#waitingToBeSent.length + this.#waitingForReply.length >= this.#maxLength ?
Promise.reject(new Error('The queue is full')) :
undefined;
}
addCommand<T = unknown>(args: Array<string>, options?: AddCommandOptions): Promise<T> {
return this.addEncodedCommand(
return this.#isQueueFull<T>() || this.addEncodedCommand(
RedisCommandsQueue.encodeCommand(args),
options
);
}
addEncodedCommand<T = unknown>(encodedCommand: string, options?: AddCommandOptions): Promise<T> {
const fullQueuePromise = this.#isQueueFull<T>();
if (fullQueuePromise) {
return fullQueuePromise;
}
return new Promise((resolve, reject) => {
const node = new LinkedList.Node<CommandWaitingToBeSent>({
encodedCommand,