Skip to content

Commit 0e7713f

Browse files
tuananhluin
authored andcommitted
feat: add maxLoadingRetryTime option when redis server not ready (#784)
And default this option to 10000ms
1 parent 5099e39 commit 0e7713f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/redis.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ var PromiseContainer = require('./promiseContainer');
7979
* @param {string} [options.keyPrefix=''] - The prefix to prepend to all keys in a command.
8080
* @param {function} [options.retryStrategy] - See "Quick Start" section
8181
* @param {number} [options.maxRetriesPerRequest] - See "Quick Start" section
82+
* @param {number} [options.maxLoadingRetryTime=10000] - when redis server is not ready, we will wait for
83+
* `loading_eta_seconds` from `info` command or maxLoadingRetryTime (milliseconds), whichever is smaller.
8284
* @param {function} [options.reconnectOnError] - See "Quick Start" section
8385
* @param {boolean} [options.readOnly=false] - Enable READONLY mode for the connection.
8486
* Only available for cluster mode.
@@ -185,7 +187,8 @@ Redis.defaultOptions = {
185187
reconnectOnError: null,
186188
readOnly: false,
187189
stringNumbers: false,
188-
maxRetriesPerRequest: 20
190+
maxRetriesPerRequest: 20,
191+
maxLoadingRetryTime: 10000
189192
};
190193

191194
Redis.prototype.resetCommandQueue = function () {
@@ -451,7 +454,10 @@ Redis.prototype._readyCheck = function (callback) {
451454
if (!info.loading || info.loading === '0') {
452455
callback(null, info);
453456
} else {
454-
var retryTime = (info.loading_eta_seconds || 1) * 1000;
457+
var loadingEtaMs = (info.loading_eta_seconds || 1) * 1000;
458+
var retryTime = _this.options.maxLoadingRetryTime && _this.options.maxLoadingRetryTime < loadingEtaMs
459+
? _this.options.maxLoadingRetryTime
460+
: loadingEtaMs
455461
debug('Redis server still loading, trying again in ' + retryTime + 'ms');
456462
setTimeout(function () {
457463
_this._readyCheck(callback);

0 commit comments

Comments
 (0)