From 72fd80430486d14042acf19ee6216659fbb63346 Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Mon, 8 Feb 2016 14:28:09 +0800 Subject: [PATCH] fix(cluster): set retryDelayOnFailover from 2000ms to 200ms --- API.md | 8 ++++---- lib/cluster/index.js | 8 ++++---- test/functional/cluster.js | 12 +++++++----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/API.md b/API.md index 7984c102..1dbd2797 100644 --- a/API.md +++ b/API.md @@ -216,11 +216,11 @@ Creates a Redis Cluster instance | options | Object | | | | [options.enableOfflineQueue] | boolean | true | See Redis class | | [options.lazyConnect] | boolean | false | See Redis class | -| [options.scaleReads] | string | "\"masters\"" | Scale reads to the node with the specified role. Available values are "masters", "slaves" and "all". | +| [options.scaleReads] | string | "masters" | Scale reads to the node with the specified role. Available values are "masters", "slaves" and "all". | | [options.maxRedirections] | number | 16 | When a MOVED or ASK error is received, client will redirect the command to another node. This option limits the max redirections allowed to send a command. | | [options.clusterRetryStrategy] | function | | See "Quick Start" section | -| [options.retryDelayOnFailover] | number | 2000 | When an error is received when sending a command(e.g. "Connection is closed." when the target Redis node is down), | -| [options.retryDelayOnClusterDown] | number | 1000 | When a CLUSTERDOWN error is received, client will retry if `retryDelayOnClusterDown` is valid delay time. | +| [options.retryDelayOnFailover] | number | 100 | When an error is received when sending a command(e.g. "Connection is closed." when the target Redis node is down), | +| [options.retryDelayOnClusterDown] | number | 100 | When a CLUSTERDOWN error is received, client will retry if `retryDelayOnClusterDown` is valid delay time. | ### cluster.connect() ⇒ Promise @@ -244,7 +244,7 @@ Get nodes with the specified role | Param | Type | Default | Description | | --- | --- | --- | --- | -| [role] | string | "\"all\"" | role, "masters", "slaves" or "all" | +| [role] | string | "all" | role, "masters", "slaves" or "all" | ### cluster.getBuiltinCommands() ⇒ Array.<string> diff --git a/lib/cluster/index.js b/lib/cluster/index.js index 8925d4d2..b147cef1 100644 --- a/lib/cluster/index.js +++ b/lib/cluster/index.js @@ -27,9 +27,9 @@ var ConnectionPool = require('./connection_pool'); * @param {number} [options.maxRedirections=16] - When a MOVED or ASK error is received, client will redirect the * command to another node. This option limits the max redirections allowed to send a command. * @param {function} [options.clusterRetryStrategy] - See "Quick Start" section - * @param {number} [options.retryDelayOnFailover=2000] - When an error is received when sending a command(e.g. + * @param {number} [options.retryDelayOnFailover=100] - When an error is received when sending a command(e.g. * "Connection is closed." when the target Redis node is down), - * @param {number} [options.retryDelayOnClusterDown=1000] - When a CLUSTERDOWN error is received, client will retry + * @param {number} [options.retryDelayOnClusterDown=100] - When a CLUSTERDOWN error is received, client will retry * if `retryDelayOnClusterDown` is valid delay time. * @extends [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter) * @extends Commander @@ -103,8 +103,8 @@ function Cluster(startupNodes, options) { */ Cluster.defaultOptions = { maxRedirections: 16, - retryDelayOnFailover: 2000, - retryDelayOnClusterDown: 1000, + retryDelayOnFailover: 100, + retryDelayOnClusterDown: 100, scaleReads: 'masters', enableOfflineQueue: true, clusterRetryStrategy: function (times) { diff --git a/test/functional/cluster.js b/test/functional/cluster.js index edc41fba..5c9bc56f 100644 --- a/test/functional/cluster.js +++ b/test/functional/cluster.js @@ -339,12 +339,11 @@ describe('cluster', function () { }); it('should be able to redirect a command to a unknown node', function (done) { - var slotTable = [ - [0, 16383, ['127.0.0.1', 30001]] - ]; var node1 = new MockServer(30001, function (argv) { if (argv[0] === 'cluster' && argv[1] === 'slots') { - return slotTable; + return [ + [0, 16383, ['127.0.0.1', 30001]] + ]; } if (argv[0] === 'get' && argv[1] === 'foo') { return new Error('MOVED ' + utils.calcSlot('foo') + ' 127.0.0.1:30002'); @@ -352,7 +351,10 @@ describe('cluster', function () { }); var node2 = new MockServer(30002, function (argv) { if (argv[0] === 'cluster' && argv[1] === 'slots') { - return slotTable; + return [ + [0, 16381, ['127.0.0.1', 30001]], + [16382, 16383, ['127.0.0.1', 30002]] + ]; } if (argv[0] === 'get' && argv[1] === 'foo') { return 'bar';