Skip to content

Commit

Permalink
feat: add maxLoadingRetryTime option when redis server not ready (#784)
Browse files Browse the repository at this point in the history
And default this option to 10000ms
  • Loading branch information
tuananh authored and luin committed Jan 21, 2019
1 parent 5099e39 commit 0e7713f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ var PromiseContainer = require('./promiseContainer');
* @param {string} [options.keyPrefix=''] - The prefix to prepend to all keys in a command.
* @param {function} [options.retryStrategy] - See "Quick Start" section
* @param {number} [options.maxRetriesPerRequest] - See "Quick Start" section
* @param {number} [options.maxLoadingRetryTime=10000] - when redis server is not ready, we will wait for
* `loading_eta_seconds` from `info` command or maxLoadingRetryTime (milliseconds), whichever is smaller.
* @param {function} [options.reconnectOnError] - See "Quick Start" section
* @param {boolean} [options.readOnly=false] - Enable READONLY mode for the connection.
* Only available for cluster mode.
Expand Down Expand Up @@ -185,7 +187,8 @@ Redis.defaultOptions = {
reconnectOnError: null,
readOnly: false,
stringNumbers: false,
maxRetriesPerRequest: 20
maxRetriesPerRequest: 20,
maxLoadingRetryTime: 10000
};

Redis.prototype.resetCommandQueue = function () {
Expand Down Expand Up @@ -451,7 +454,10 @@ Redis.prototype._readyCheck = function (callback) {
if (!info.loading || info.loading === '0') {
callback(null, info);
} else {
var retryTime = (info.loading_eta_seconds || 1) * 1000;
var loadingEtaMs = (info.loading_eta_seconds || 1) * 1000;
var retryTime = _this.options.maxLoadingRetryTime && _this.options.maxLoadingRetryTime < loadingEtaMs
? _this.options.maxLoadingRetryTime
: loadingEtaMs
debug('Redis server still loading, trying again in ' + retryTime + 'ms');
setTimeout(function () {
_this._readyCheck(callback);
Expand Down

0 comments on commit 0e7713f

Please sign in to comment.