From 1d31314dbe56a9790fc7887b13ecf1bc71a70001 Mon Sep 17 00:00:00 2001 From: Michael O'Keefe Date: Fri, 3 Mar 2023 11:59:51 -0500 Subject: [PATCH 1/2] Reconnect when readonly error is received --- lib/db.js | 10 ++++++++-- package.json | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/db.js b/lib/db.js index 674fbf0..2e0bbf6 100644 --- a/lib/db.js +++ b/lib/db.js @@ -36,7 +36,13 @@ class LimitDBRedis extends EventEmitter { enableOfflineQueue: false, keyPrefix: config.prefix, password: config.password, - tls: config.tls + tls: config.tls, + reconnectOnError: (err) => { + // will force a reconnect when error starts with `READONLY` + // this code is only triggered when auto-failover is disabled + // more: https://github.com/luin/ioredis#reconnect-on-error + return err.message.indexOf('READONLY') === 0; + }, }; const clusterOptions = { @@ -325,7 +331,7 @@ class LimitDBRedis extends EventEmitter { }, callback); } - _determineCount({paramsCount, defaultCount, bucketKeyConfigSize}) { + _determineCount({ paramsCount, defaultCount, bucketKeyConfigSize }) { if (paramsCount === 'all') { return bucketKeyConfigSize; } diff --git a/package.json b/package.json index e40fe3a..e23ff93 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "dependencies": { "async": "^2.6.1", "disyuntor": "^3.5.0", - "ioredis": "^4.5.1", + "ioredis": "^4.28.5", "lodash": "^4.17.15", "lru-cache": "^4.1.5", "ms": "^2.1.2", From 37088f72b0207489f6e3788641779eb1852ac569 Mon Sep 17 00:00:00 2001 From: Michael O'Keefe Date: Mon, 6 Mar 2023 08:54:41 -0500 Subject: [PATCH 2/2] Update err message check to follow the docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the docs uses `includes` rather than `indexOf` Co-authored-by: Carlos Campderrós --- lib/db.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/db.js b/lib/db.js index 2e0bbf6..6387f20 100644 --- a/lib/db.js +++ b/lib/db.js @@ -41,7 +41,7 @@ class LimitDBRedis extends EventEmitter { // will force a reconnect when error starts with `READONLY` // this code is only triggered when auto-failover is disabled // more: https://github.com/luin/ioredis#reconnect-on-error - return err.message.indexOf('READONLY') === 0; + return err.message.includes('READONLY'); }, };