ioredis 4.29.1 → 4.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1007,7 +1007,7 @@ cluster.get("foo", (err, res) => {
1007
1007
  state stabilized after a failover, so adding a delay before resending can prevent a ping pong effect.
1008
1008
  - `redisOptions`: Default options passed to the constructor of `Redis` when connecting to a node.
1009
1009
  - `slotsRefreshTimeout`: Milliseconds before a timeout occurs while refreshing slots from the cluster (default `1000`).
1010
- - `slotsRefreshInterval`: Milliseconds between every automatic slots refresh (default `5000`).
1010
+ - `slotsRefreshInterval`: Milliseconds between every automatic slots refresh (default `5000`), setting it to a negative value will disable the slots refresh.
1011
1011
 
1012
1012
  ### Read-write splitting
1013
1013
 
@@ -41,6 +41,7 @@ class Cluster extends events_1.EventEmitter {
41
41
  this.delayQueue = new DelayQueue_1.default();
42
42
  this.offlineQueue = new Deque();
43
43
  this.isRefreshing = false;
44
+ this._refreshSlotsCacheCallbacks = [];
44
45
  this.isCluster = true;
45
46
  this._autoPipelines = new Map();
46
47
  this._groupsIds = {};
@@ -110,7 +111,7 @@ class Cluster extends events_1.EventEmitter {
110
111
  }
111
112
  }
112
113
  resetNodesRefreshInterval() {
113
- if (this.slotsTimer) {
114
+ if (this.slotsTimer || this.options.slotsRefreshInterval < 0) {
114
115
  return;
115
116
  }
116
117
  const nextRound = () => {
@@ -198,12 +199,12 @@ class Cluster extends events_1.EventEmitter {
198
199
  this.once("refresh", refreshListener);
199
200
  this.once("close", closeListener);
200
201
  this.once("close", this.handleCloseEvent.bind(this));
201
- this.refreshSlotsCache(function (err) {
202
+ this.refreshSlotsCache((err) => {
202
203
  if (err && err.message === "Failed to refresh slots cache.") {
203
204
  redis_1.default.prototype.silentEmit.call(this, "error", err);
204
205
  this.connectionPool.reset([]);
205
206
  }
206
- }.bind(this));
207
+ });
207
208
  this.subscriber.start();
208
209
  if (this.options.shardedSubscribers) {
209
210
  this.shardedSubscribers.start();
@@ -389,23 +390,23 @@ class Cluster extends events_1.EventEmitter {
389
390
  * @memberof Cluster
390
391
  */
391
392
  refreshSlotsCache(callback) {
393
+ if (typeof callback === "function") {
394
+ this._refreshSlotsCacheCallbacks.push(callback);
395
+ }
392
396
  if (this.isRefreshing) {
393
- if (typeof callback === "function") {
394
- process.nextTick(callback);
395
- }
396
397
  return;
397
398
  }
398
399
  this.isRefreshing = true;
399
- const _this = this;
400
- const wrapper = function (error) {
401
- _this.isRefreshing = false;
402
- if (typeof callback === "function") {
400
+ const wrapper = (error) => {
401
+ this.isRefreshing = false;
402
+ for (const callback of this._refreshSlotsCacheCallbacks) {
403
403
  callback(error);
404
404
  }
405
+ this._refreshSlotsCacheCallbacks = [];
405
406
  };
406
407
  const nodes = utils_2.shuffle(this.connectionPool.getNodes());
407
408
  let lastNodeError = null;
408
- function tryNode(index) {
409
+ const tryNode = (index) => {
409
410
  if (index === nodes.length) {
410
411
  const error = new ClusterAllFailedError_1.default("Failed to refresh slots cache.", lastNodeError);
411
412
  return wrapper(error);
@@ -413,8 +414,8 @@ class Cluster extends events_1.EventEmitter {
413
414
  const node = nodes[index];
414
415
  const key = `${node.options.host}:${node.options.port}`;
415
416
  debug("getting slot cache from %s", key);
416
- _this.getInfoFromNode(node, function (err) {
417
- switch (_this.status) {
417
+ this.getInfoFromNode(node, (err) => {
418
+ switch (this.status) {
418
419
  case "close":
419
420
  case "end":
420
421
  return wrapper(new Error("Cluster is disconnected."));
@@ -422,16 +423,16 @@ class Cluster extends events_1.EventEmitter {
422
423
  return wrapper(new Error("Cluster is disconnecting."));
423
424
  }
424
425
  if (err) {
425
- _this.emit("node error", err, key);
426
+ this.emit("node error", err, key);
426
427
  lastNodeError = err;
427
428
  tryNode(index + 1);
428
429
  }
429
430
  else {
430
- _this.emit("refresh");
431
+ this.emit("refresh");
431
432
  wrapper();
432
433
  }
433
434
  });
434
- }
435
+ };
435
436
  tryNode(0);
436
437
  }
437
438
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ioredis",
3
- "version": "4.29.1",
3
+ "version": "4.30.0",
4
4
  "description": "A robust, performance-focused and full-featured Redis client for Node.js.",
5
5
  "main": "built/index.js",
6
6
  "files": [