From d136813b59b1e928bc14f296ce6606f1aa69068d Mon Sep 17 00:00:00 2001 From: nodegin <10@nodeg.in> Date: Fri, 9 Feb 2024 16:24:00 +0900 Subject: [PATCH 1/4] Update Redis.ts --- lib/Redis.ts | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/Redis.ts b/lib/Redis.ts index ff7cf29b..e5dc3634 100644 --- a/lib/Redis.ts +++ b/lib/Redis.ts @@ -637,18 +637,27 @@ 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 self = this; + const resendCommand = () => { + if (self.status !== "reconnecting") { + self.disconnect(true); + } + if (((_a = self.condition) === null || _a === void 0 ? void 0 : _a.select) !== item.select && + item.command.name !== "select") { + self.select(item.select); + } + // TODO + // @ts-expect-error + self.sendCommand(item.command); + }; + const retryDelay = self.options.retryStrategy(++self.retryAttempts); + if (typeof self.options.retryStrategy !== "function") { + return resendCommand(); } - // TODO - // @ts-expect-error - this.sendCommand(item.command); + self.reconnectTimeout = setTimeout(function () { + self.reconnectTimeout = null; + resendCommand(); + }, retryDelay); break; default: item.command.reject(err); From 6b295e16f22279627a1ca354acce4879e9ceef8e Mon Sep 17 00:00:00 2001 From: nodegin <10@nodeg.in> Date: Fri, 9 Feb 2024 16:29:08 +0900 Subject: [PATCH 2/4] Fix wrong line --- lib/Redis.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Redis.ts b/lib/Redis.ts index e5dc3634..4cd82919 100644 --- a/lib/Redis.ts +++ b/lib/Redis.ts @@ -650,10 +650,10 @@ class Redis extends Commander implements DataHandledable { // @ts-expect-error self.sendCommand(item.command); }; - const retryDelay = self.options.retryStrategy(++self.retryAttempts); if (typeof self.options.retryStrategy !== "function") { return resendCommand(); } + const retryDelay = self.options.retryStrategy(++self.retryAttempts); self.reconnectTimeout = setTimeout(function () { self.reconnectTimeout = null; resendCommand(); From 01f2747c6ff481f60164e9bcf62acf66107edc85 Mon Sep 17 00:00:00 2001 From: nodegin <10@nodeg.in> Date: Fri, 9 Feb 2024 16:30:41 +0900 Subject: [PATCH 3/4] Use this instead of self --- lib/Redis.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/Redis.ts b/lib/Redis.ts index 4cd82919..b1db2776 100644 --- a/lib/Redis.ts +++ b/lib/Redis.ts @@ -637,25 +637,24 @@ class Redis extends Commander implements DataHandledable { item.command.reject(err); break; case 2: - const self = this; const resendCommand = () => { - if (self.status !== "reconnecting") { - self.disconnect(true); + if (this.status !== "reconnecting") { + this.disconnect(true); } - if (((_a = self.condition) === null || _a === void 0 ? void 0 : _a.select) !== item.select && + if (((_a = this.condition) === null || _a === void 0 ? void 0 : _a.select) !== item.select && item.command.name !== "select") { - self.select(item.select); + this.select(item.select); } // TODO // @ts-expect-error - self.sendCommand(item.command); + this.sendCommand(item.command); }; - if (typeof self.options.retryStrategy !== "function") { + if (typeof this.options.retryStrategy !== "function") { return resendCommand(); } - const retryDelay = self.options.retryStrategy(++self.retryAttempts); - self.reconnectTimeout = setTimeout(function () { - self.reconnectTimeout = null; + const retryDelay = this.options.retryStrategy(++this.retryAttempts); + this.reconnectTimeout = setTimeout(() => { + this.reconnectTimeout = null; resendCommand(); }, retryDelay); break; From 8f6672a7d79e5021344ab7af53991334d65342ae Mon Sep 17 00:00:00 2001 From: nodegin <10@nodeg.in> Date: Fri, 9 Feb 2024 16:42:18 +0900 Subject: [PATCH 4/4] Update Redis.ts --- lib/Redis.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Redis.ts b/lib/Redis.ts index b1db2776..1b6c54c0 100644 --- a/lib/Redis.ts +++ b/lib/Redis.ts @@ -641,8 +641,10 @@ class Redis extends Commander implements DataHandledable { if (this.status !== "reconnecting") { this.disconnect(true); } - if (((_a = this.condition) === null || _a === void 0 ? void 0 : _a.select) !== item.select && - item.command.name !== "select") { + if ( + this.condition?.select !== item.select && + item.command.name !== "select" + ) { this.select(item.select); } // TODO