From cfe425843d297b9aadfd43d24d1e54befdbf1b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E9=AA=85?= Date: Sat, 30 Jun 2018 22:53:02 +0800 Subject: [PATCH] fix(Cluster): issues when setting enableOfflineQueue to false (#649) Offline queue should be enabled on the internal cluster nodes so that we don't need to wait for the `ready` event before sending commands to the node. --- lib/cluster/connection_pool.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/cluster/connection_pool.js b/lib/cluster/connection_pool.js index 82c5ba5f..d06cf83d 100644 --- a/lib/cluster/connection_pool.js +++ b/lib/cluster/connection_pool.js @@ -46,7 +46,7 @@ ConnectionPool.prototype.findOrCreate = function (node, readOnly) { redis = this.nodes.all[node.key]; if (redis.options.readOnly !== readOnly) { redis.options.readOnly = readOnly; - debug('Change role of %s to %s', node.key, readOnly ? 'slave' : 'master') + debug('Change role of %s to %s', node.key, readOnly ? 'slave' : 'master'); redis[readOnly ? 'readonly' : 'readwrite']().catch(_.noop); if (readOnly) { delete this.nodes.master[node.key]; @@ -59,7 +59,14 @@ ConnectionPool.prototype.findOrCreate = function (node, readOnly) { } else { debug('Connecting to %s as %s', node.key, readOnly ? 'slave' : 'master'); redis = new Redis(_.defaults({ + // Never try to reconnect when a node is lose, + // instead, waiting for a `MOVED` error and + // fetch the slots again. retryStrategy: null, + // Offline queue should be enabled so that + // we don't need to wait for the `ready` event + // before sending commands to the node. + enableOfflineQueue: true, readOnly: readOnly }, node, this.redisOptions, { lazyConnect: true })); this.nodes.all[node.key] = redis;