diff --git a/lib/services/redis.js b/lib/services/redis.js index 5ca8c83db2..78679cf7d7 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}); + const 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 => { // eslint-disable-line no-loop-func + 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;