From d456a37402ce416c8d12bd0d71d8200780edee68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Vidis?= Date: Tue, 2 Apr 2019 10:26:13 +0200 Subject: [PATCH 1/3] [bugfix] scan keys on redis cluster --- lib/services/redis.js | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/services/redis.js b/lib/services/redis.js index 5ca8c83db2..6fe17a5aee 100644 --- a/lib/services/redis.js +++ b/lib/services/redis.js @@ -164,18 +164,22 @@ class Redis extends Service { * @returns {Promise} promise resolving to an array of keys */ searchKeys(pattern) { - return new Bluebird(resolve => { + if (this._client instanceof IORedis.Cluster) { let keys = []; - const stream = this._client.scanStream({match: pattern}); + let promises = []; - stream.on('data', resultKeys => { - keys = keys.concat(resultKeys); - }); + for (const node of this._client.nodes('master')) { + promises.push(this._searchNodeKeys(node, pattern) + .then(nodeKeys => { + keys = keys.concat(nodeKeys); + })); + } - stream.on('end', () => { - resolve(_.uniq(keys)); - }); - }); + return Bluebird.all(promises) + .then(() => _.uniq(keys)); + } + + return this._searchNodeKeys(this._client, pattern); } /** @@ -205,6 +209,23 @@ class Redis extends Service { return this._client.mget(_args); } + + _searchNodeKeys(node, pattern) { + return new Bluebird(resolve => { + let keys = []; + const stream = node.scanStream({match: pattern}); + + stream.on('data', resultKeys => { + keys = keys.concat(resultKeys); + }); + + stream.on('end', () => { + resolve(_.uniq(keys)); + }); + }); + + } + } module.exports = Redis; From 82030f6dff72a636777ec48d1b28995d46d62bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Vidis?= Date: Tue, 2 Apr 2019 16:47:18 +0200 Subject: [PATCH 2/3] sonarqube --- lib/services/redis.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/redis.js b/lib/services/redis.js index 6fe17a5aee..7847298637 100644 --- a/lib/services/redis.js +++ b/lib/services/redis.js @@ -166,7 +166,7 @@ class Redis extends Service { searchKeys(pattern) { if (this._client instanceof IORedis.Cluster) { let keys = []; - let promises = []; + const promises = []; for (const node of this._client.nodes('master')) { promises.push(this._searchNodeKeys(node, pattern) From 681d6c3f1b45175f07a1f2ec3607c8341c7001f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Vidis?= Date: Tue, 2 Apr 2019 16:50:25 +0200 Subject: [PATCH 3/3] eslint --- lib/services/redis.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/redis.js b/lib/services/redis.js index 7847298637..78679cf7d7 100644 --- a/lib/services/redis.js +++ b/lib/services/redis.js @@ -170,7 +170,7 @@ class Redis extends Service { for (const node of this._client.nodes('master')) { promises.push(this._searchNodeKeys(node, pattern) - .then(nodeKeys => { + .then(nodeKeys => { // eslint-disable-line no-loop-func keys = keys.concat(nodeKeys); })); }