diff --git a/lib/Redis.ts b/lib/Redis.ts index ff7cf29b..1b6c54c0 100644 --- a/lib/Redis.ts +++ b/lib/Redis.ts @@ -637,18 +637,28 @@ class Redis extends Commander implements DataHandledable { item.command.reject(err); break; case 2: - if (this.status !== "reconnecting") { - this.disconnect(true); - } - if ( - this.condition?.select !== item.select && - item.command.name !== "select" - ) { - this.select(item.select); + const resendCommand = () => { + if (this.status !== "reconnecting") { + this.disconnect(true); + } + if ( + this.condition?.select !== item.select && + item.command.name !== "select" + ) { + this.select(item.select); + } + // TODO + // @ts-expect-error + this.sendCommand(item.command); + }; + if (typeof this.options.retryStrategy !== "function") { + return resendCommand(); } - // TODO - // @ts-expect-error - this.sendCommand(item.command); + const retryDelay = this.options.retryStrategy(++this.retryAttempts); + this.reconnectTimeout = setTimeout(() => { + this.reconnectTimeout = null; + resendCommand(); + }, retryDelay); break; default: item.command.reject(err);