You've already forked node-redis
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:
@@ -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,
|
||||
|
Reference in New Issue
Block a user