ioredis 2.5.0 → 3.0.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/Changelog.md CHANGED
@@ -1,3 +1,60 @@
1
+ <a name="3.0.0"></a>
2
+ # [3.0.0](https://github.com/luin/ioredis/compare/v3.0.0-2...v3.0.0) (2017-05-18)
3
+
4
+
5
+ ### Features
6
+
7
+ * **pipeline:** add #length to get the command count ([a6060cb](https://github.com/luin/ioredis/commit/a6060cb)), closes [#461](https://github.com/luin/ioredis/issues/461)
8
+ * **sentinel:** allow connection to IPv6-only sentinels ([#463](https://github.com/luin/ioredis/issues/463)) ([a389f3c](https://github.com/luin/ioredis/commit/a389f3c))
9
+
10
+
11
+
12
+ <a name="3.0.0-2"></a>
13
+ # [3.0.0-2](https://github.com/luin/ioredis/compare/v3.0.0-1...v3.0.0-2) (2017-05-03)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * restore the default connectTimeout to 10000 ([dc8256e](https://github.com/luin/ioredis/commit/dc8256e))
19
+
20
+
21
+
22
+ <a name="3.0.0-1"></a>
23
+ # [3.0.0-1](https://github.com/luin/ioredis/compare/v3.0.0-0...v3.0.0-1) (2017-04-16)
24
+
25
+
26
+ ### Features
27
+
28
+ * add debug logs for resolved sentinel nodes ([8f3d3f7](https://github.com/luin/ioredis/commit/8f3d3f7))
29
+ * report error on Sentinel connection refused ([#445](https://github.com/luin/ioredis/issues/445)) ([#446](https://github.com/luin/ioredis/issues/446)) ([286a5bc](https://github.com/luin/ioredis/commit/286a5bc))
30
+ * set default port of sentinels to 26379. ([#441](https://github.com/luin/ioredis/issues/441)) ([539fe41](https://github.com/luin/ioredis/commit/539fe41))
31
+
32
+
33
+ ### BREAKING CHANGES
34
+
35
+ * The default port of sentinels are now 26379 instead of 6379. This shouldn't break your app in most case since few setups has the sentinel server running on 6379, but if it's your case and the port isn't set explicitly, please go to update it.
36
+
37
+
38
+
39
+ <a name="3.0.0-0"></a>
40
+ # [3.0.0-0](https://github.com/luin/ioredis/compare/v2.5.0...v3.0.0-0) (2017-01-26)
41
+
42
+ This is a performance-focused release. We finially switch to the new version of JavaScript parser and drop the support for hiredis (Thanks to the lovely community!).
43
+ Also, we switch to [denque](https://github.com/Salakar/denque) to improve the queueing performance.
44
+
45
+ Let us know if there's any issue when using this pre-release.
46
+
47
+ ### Other Changes
48
+
49
+ * increase the default reconnection interval ([c5fefb7](https://github.com/luin/ioredis/commit/c5fefb7)), closes [#414](https://github.com/luin/ioredis/issues/414)
50
+
51
+
52
+ ### BREAKING CHANGES
53
+
54
+ * Although the interface doesn't change after upgrading the js parser, there may be still some potential internal differences that may break the applications which rely on them. Also, force a major version bump emphasizes the dropping of the hiredis.
55
+
56
+
57
+
1
58
  <a name="2.5.0"></a>
2
59
  # [2.5.0](https://github.com/luin/ioredis/compare/v2.4.3...v2.5.0) (2017-01-06)
3
60
 
package/README.md CHANGED
@@ -225,6 +225,13 @@ redis.pipeline([
225
225
  ]).exec(function () { /* ... */ });
226
226
  ```
227
227
 
228
+ `#length` property shows how many commands in the pipeline:
229
+
230
+ ```javascript
231
+ const length = redis.pipeline().set('foo', 'bar').get('foo').length;
232
+ // length === 2
233
+ ```
234
+
228
235
 
229
236
  ## Transaction
230
237
  Most of the time, the transaction commands `multi` & `exec` are used together with pipeline.
@@ -504,7 +511,7 @@ using the `retryStrategy` option:
504
511
  var redis = new Redis({
505
512
  // This is the default value of `retryStrategy`
506
513
  retryStrategy: function (times) {
507
- var delay = Math.min(times * 2, 2000);
514
+ var delay = Math.min(times * 50, 2000);
508
515
  return delay;
509
516
  }
510
517
  });
@@ -590,7 +597,7 @@ var redis = new Redis({
590
597
 
591
598
  ## Sentinel
592
599
  ioredis supports Sentinel out of the box. It works transparently as all features that work when
593
- you connect to a single node also work when you connect to a sentinel group. Make sure to run Redis >= 2.8.12 if you want to use this feature.
600
+ you connect to a single node also work when you connect to a sentinel group. Make sure to run Redis >= 2.8.12 if you want to use this feature. Sentinels have a default port of 26379.
594
601
 
595
602
  To connect using Sentinel, use:
596
603
 
@@ -839,10 +846,6 @@ var cluster = new Redis.Cluster([
839
846
  });
840
847
  ```
841
848
 
842
- ## Improve Performance
843
- ioredis supports two parsers, "hiredis" and "javascript". Refer to https://github.com/luin/ioredis/wiki/Improve-Performance
844
- for details about the differences between them in terms of performance.
845
-
846
849
  <hr>
847
850
 
848
851
  # Error Handling
@@ -958,7 +961,7 @@ I'm happy to receive bug reports, fixes, documentation enhancements, and any oth
958
961
  And since I'm not a native English speaker, if you find any grammar mistakes in the documentation, please also let me know. :)
959
962
 
960
963
  # Contributors
961
- <table><tr><td width="20%"><a href="https://github.com/luin"><img src="https://avatars.githubusercontent.com/u/635902?v=3" /></a><p align="center">luin</p></td><td width="20%"><a href="https://github.com/dguo"><img src="https://avatars.githubusercontent.com/u/2763135?v=3" /></a><p align="center">dguo</p></td><td width="20%"><a href="https://github.com/shaharmor"><img src="https://avatars.githubusercontent.com/u/10861920?v=3" /></a><p align="center">shaharmor</p></td><td width="20%"><a href="https://github.com/doublesharp"><img src="https://avatars.githubusercontent.com/u/571472?v=3" /></a><p align="center">doublesharp</p></td><td width="20%"><a href="https://github.com/nakulgan"><img src="https://avatars.githubusercontent.com/u/189836?v=3" /></a><p align="center">nakulgan</p></td></tr><tr><td width="20%"><a href="https://github.com/AVVS"><img src="https://avatars.githubusercontent.com/u/1713617?v=3" /></a><p align="center">AVVS</p></td><td width="20%"><a href="https://github.com/ramonsnir"><img src="https://avatars.githubusercontent.com/u/1024028?v=3" /></a><p align="center">ramonsnir</p></td><td width="20%"><a href="https://github.com/hayeah"><img src="https://avatars.githubusercontent.com/u/50120?v=3" /></a><p align="center">hayeah</p></td><td width="20%"><a href="https://github.com/albin3"><img src="https://avatars.githubusercontent.com/u/6190670?v=3" /></a><p align="center">albin3</p></td><td width="20%"><a href="https://github.com/phlip9"><img src="https://avatars.githubusercontent.com/u/918989?v=3" /></a><p align="center">phlip9</p></td></tr><tr><td width="20%"><a href="https://github.com/fracmak"><img src="https://avatars.githubusercontent.com/u/378178?v=3" /></a><p align="center">fracmak</p></td><td width="20%"><a href="https://github.com/ddunkin"><img src="https://avatars.githubusercontent.com/u/264744?v=3" /></a><p align="center">ddunkin</p></td><td width="20%"><a href="https://github.com/ruimarinho"><img src="https://avatars.githubusercontent.com/u/288709?v=3" /></a><p align="center">ruimarinho</p></td><td width="20%"><a href="https://github.com/suprememoocow"><img src="https://avatars.githubusercontent.com/u/594566?v=3" /></a><p align="center">suprememoocow</p></td><td width="20%"><a href="https://github.com/jpallen"><img src="https://avatars.githubusercontent.com/u/31305?v=3" /></a><p align="center">jpallen</p></td></tr><tr><td width="20%"><a href="https://github.com/lpinca"><img src="https://avatars.githubusercontent.com/u/1443911?v=3" /></a><p align="center">lpinca</p></td><td width="20%"><a href="https://github.com/jeffjen"><img src="https://avatars.githubusercontent.com/u/5814507?v=3" /></a><p align="center">jeffjen</p></td><td width="20%"><a href="https://github.com/headquarters"><img src="https://avatars.githubusercontent.com/u/347079?v=3" /></a><p align="center">headquarters</p></td><td width="20%"><a href="https://github.com/devaos"><img src="https://avatars.githubusercontent.com/u/5412167?v=3" /></a><p align="center">devaos</p></td><td width="20%"><a href="https://github.com/9point6"><img src="https://avatars.githubusercontent.com/u/627697?v=3" /></a><p align="center">9point6</p></td></tr><tr><td width="20%"><a href="https://github.com/darrachequesne"><img src="https://avatars.githubusercontent.com/u/13031701?v=3" /></a><p align="center">darrachequesne</p></td><td width="20%"><a href="https://github.com/horx"><img src="https://avatars.githubusercontent.com/u/1332618?v=3" /></a><p align="center">horx</p></td><td width="20%"><a href="https://github.com/ColmHally"><img src="https://avatars.githubusercontent.com/u/20333?v=3" /></a><p align="center">ColmHally</p></td><td width="20%"><a href="https://github.com/klinquist"><img src="https://avatars.githubusercontent.com/u/1343376?v=3" /></a><p align="center">klinquist</p></td><td width="20%"><a href="https://github.com/alsotang"><img src="https://avatars.githubusercontent.com/u/1147375?v=3" /></a><p align="center">alsotang</p></td></tr><tr><td width="20%"><a href="https://github.com/zhuangya"><img src="https://avatars.githubusercontent.com/u/499038?v=3" /></a><p align="center">zhuangya</p></td><td width="20%"><a href="https://github.com/Gerhut"><img src="https://avatars.githubusercontent.com/u/2500247?v=3" /></a><p align="center">Gerhut</p></td><td width="20%"><a href="https://github.com/jcperez"><img src="https://avatars.githubusercontent.com/u/4073359?v=3" /></a><p align="center">jcperez</p></td><td width="20%"><a href="https://github.com/pensierinmusica"><img src="https://avatars.githubusercontent.com/u/3594037?v=3" /></a><p align="center">pensierinmusica</p></td><td width="20%"><a href="https://github.com/TeeAaTeeUu"><img src="https://avatars.githubusercontent.com/u/997511?v=3" /></a><p align="center">TeeAaTeeUu</p></td></tr><tr><td width="20%"><a href="https://github.com/bradvogel"><img src="https://avatars.githubusercontent.com/u/821706?v=3" /></a><p align="center">bradvogel</p></td><td width="20%"><a href="https://github.com/devoto13"><img src="https://avatars.githubusercontent.com/u/823594?v=3" /></a><p align="center">devoto13</p></td><td width="20%"><a href="https://github.com/tkalfigo"><img src="https://avatars.githubusercontent.com/u/3481553?v=3" /></a><p align="center">tkalfigo</p></td><td width="20%"><a href="https://github.com/stipsan"><img src="https://avatars.githubusercontent.com/u/81981?v=3" /></a><p align="center">stipsan</p></td><td width="20%"><a href="https://github.com/ArtskydJ"><img src="https://avatars.githubusercontent.com/u/1833684?v=3" /></a><p align="center">ArtskydJ</p></td></tr><tr><td width="20%"><a href="https://github.com/joeledwards"><img src="https://avatars.githubusercontent.com/u/412853?v=3" /></a><p align="center">joeledwards</p></td><td width="20%"><a href="https://github.com/nswbmw"><img src="https://avatars.githubusercontent.com/u/4279697?v=3" /></a><p align="center">nswbmw</p></td><td width="20%"><a href="https://github.com/pyros2097"><img src="https://avatars.githubusercontent.com/u/1687946?v=3" /></a><p align="center">pyros2097</p></td><td width="20%"><a href="https://github.com/henstock"><img src="https://avatars.githubusercontent.com/u/13809467?v=3" /></a><p align="center">henstock</p></td><td width="20%"><a href="https://github.com/igrcic"><img src="https://avatars.githubusercontent.com/u/394398?v=3" /></a><p align="center">igrcic</p></td></tr><tr><td width="20%"><a href="https://github.com/mtlima"><img src="https://avatars.githubusercontent.com/u/9111440?v=3" /></a><p align="center">mtlima</p></td><td width="20%"><a href="https://github.com/pra85"><img src="https://avatars.githubusercontent.com/u/829526?v=3" /></a><p align="center">pra85</p></td><td width="20%"><a href="https://github.com/i5ting"><img src="https://avatars.githubusercontent.com/u/3118295?v=3" /></a><p align="center">i5ting</p></td><td width="20%"><a href="https://github.com/VikramTiwari"><img src="https://avatars.githubusercontent.com/u/1330677?v=3" /></a><p align="center">VikramTiwari</p></td></table>
964
+ <table><tr><td width="20%"><a href="https://github.com/luin"><img src="https://avatars1.githubusercontent.com/u/635902?v=3" /></a><p align="center">luin</p></td><td width="20%"><a href="https://github.com/dguo"><img src="https://avatars3.githubusercontent.com/u/2763135?v=3" /></a><p align="center">dguo</p></td><td width="20%"><a href="https://github.com/shaharmor"><img src="https://avatars0.githubusercontent.com/u/10861920?v=3" /></a><p align="center">shaharmor</p></td><td width="20%"><a href="https://github.com/doublesharp"><img src="https://avatars0.githubusercontent.com/u/571472?v=3" /></a><p align="center">doublesharp</p></td><td width="20%"><a href="https://github.com/nakulgan"><img src="https://avatars0.githubusercontent.com/u/189836?v=3" /></a><p align="center">nakulgan</p></td></tr><tr><td width="20%"><a href="https://github.com/AVVS"><img src="https://avatars2.githubusercontent.com/u/1713617?v=3" /></a><p align="center">AVVS</p></td><td width="20%"><a href="https://github.com/ramonsnir"><img src="https://avatars2.githubusercontent.com/u/1024028?v=3" /></a><p align="center">ramonsnir</p></td><td width="20%"><a href="https://github.com/hayeah"><img src="https://avatars1.githubusercontent.com/u/50120?v=3" /></a><p align="center">hayeah</p></td><td width="20%"><a href="https://github.com/albin3"><img src="https://avatars0.githubusercontent.com/u/6190670?v=3" /></a><p align="center">albin3</p></td><td width="20%"><a href="https://github.com/phlip9"><img src="https://avatars3.githubusercontent.com/u/918989?v=3" /></a><p align="center">phlip9</p></td></tr><tr><td width="20%"><a href="https://github.com/fracmak"><img src="https://avatars2.githubusercontent.com/u/378178?v=3" /></a><p align="center">fracmak</p></td><td width="20%"><a href="https://github.com/ddunkin"><img src="https://avatars1.githubusercontent.com/u/264744?v=3" /></a><p align="center">ddunkin</p></td><td width="20%"><a href="https://github.com/ruimarinho"><img src="https://avatars3.githubusercontent.com/u/288709?v=3" /></a><p align="center">ruimarinho</p></td><td width="20%"><a href="https://github.com/suprememoocow"><img src="https://avatars3.githubusercontent.com/u/594566?v=3" /></a><p align="center">suprememoocow</p></td><td width="20%"><a href="https://github.com/jpallen"><img src="https://avatars3.githubusercontent.com/u/31305?v=3" /></a><p align="center">jpallen</p></td></tr><tr><td width="20%"><a href="https://github.com/lpinca"><img src="https://avatars3.githubusercontent.com/u/1443911?v=3" /></a><p align="center">lpinca</p></td><td width="20%"><a href="https://github.com/reconbot"><img src="https://avatars1.githubusercontent.com/u/25966?v=3" /></a><p align="center">reconbot</p></td><td width="20%"><a href="https://github.com/frankvm04"><img src="https://avatars2.githubusercontent.com/u/796475?v=3" /></a><p align="center">frankvm04</p></td><td width="20%"><a href="https://github.com/jeffjen"><img src="https://avatars0.githubusercontent.com/u/5814507?v=3" /></a><p align="center">jeffjen</p></td><td width="20%"><a href="https://github.com/SamBergeron"><img src="https://avatars2.githubusercontent.com/u/3879294?v=3" /></a><p align="center">SamBergeron</p></td></tr><tr><td width="20%"><a href="https://github.com/seoker"><img src="https://avatars2.githubusercontent.com/u/7975797?v=3" /></a><p align="center">seoker</p></td><td width="20%"><a href="https://github.com/devaos"><img src="https://avatars3.githubusercontent.com/u/5412167?v=3" /></a><p align="center">devaos</p></td><td width="20%"><a href="https://github.com/headquarters"><img src="https://avatars3.githubusercontent.com/u/347079?v=3" /></a><p align="center">headquarters</p></td><td width="20%"><a href="https://github.com/9point6"><img src="https://avatars2.githubusercontent.com/u/627697?v=3" /></a><p align="center">9point6</p></td><td width="20%"><a href="https://github.com/horx"><img src="https://avatars1.githubusercontent.com/u/1332618?v=3" /></a><p align="center">horx</p></td></tr><tr><td width="20%"><a href="https://github.com/darrachequesne"><img src="https://avatars0.githubusercontent.com/u/13031701?v=3" /></a><p align="center">darrachequesne</p></td><td width="20%"><a href="https://github.com/klinquist"><img src="https://avatars1.githubusercontent.com/u/1343376?v=3" /></a><p align="center">klinquist</p></td><td width="20%"><a href="https://github.com/ColmHally"><img src="https://avatars0.githubusercontent.com/u/20333?v=3" /></a><p align="center">ColmHally</p></td><td width="20%"><a href="https://github.com/alsotang"><img src="https://avatars2.githubusercontent.com/u/1147375?v=3" /></a><p align="center">alsotang</p></td><td width="20%"><a href="https://github.com/zhuangya"><img src="https://avatars1.githubusercontent.com/u/499038?v=3" /></a><p align="center">zhuangya</p></td></tr><tr><td width="20%"><a href="https://github.com/Gerhut"><img src="https://avatars2.githubusercontent.com/u/2500247?v=3" /></a><p align="center">Gerhut</p></td><td width="20%"><a href="https://github.com/jcperez"><img src="https://avatars3.githubusercontent.com/u/4073359?v=3" /></a><p align="center">jcperez</p></td><td width="20%"><a href="https://github.com/TeeAaTeeUu"><img src="https://avatars2.githubusercontent.com/u/997511?v=3" /></a><p align="center">TeeAaTeeUu</p></td><td width="20%"><a href="https://github.com/pensierinmusica"><img src="https://avatars2.githubusercontent.com/u/3594037?v=3" /></a><p align="center">pensierinmusica</p></td><td width="20%"><a href="https://github.com/i5ting"><img src="https://avatars0.githubusercontent.com/u/3118295?v=3" /></a><p align="center">i5ting</p></td></tr><tr><td width="20%"><a href="https://github.com/devoto13"><img src="https://avatars2.githubusercontent.com/u/823594?v=3" /></a><p align="center">devoto13</p></td><td width="20%"><a href="https://github.com/ArtskydJ"><img src="https://avatars1.githubusercontent.com/u/1833684?v=3" /></a><p align="center">ArtskydJ</p></td><td width="20%"><a href="https://github.com/stipsan"><img src="https://avatars1.githubusercontent.com/u/81981?v=3" /></a><p align="center">stipsan</p></td><td width="20%"><a href="https://github.com/henstock"><img src="https://avatars0.githubusercontent.com/u/13809467?v=3" /></a><p align="center">henstock</p></td><td width="20%"><a href="https://github.com/tkalfigo"><img src="https://avatars1.githubusercontent.com/u/3481553?v=3" /></a><p align="center">tkalfigo</p></td></tr><tr><td width="20%"><a href="https://github.com/igrcic"><img src="https://avatars2.githubusercontent.com/u/394398?v=3" /></a><p align="center">igrcic</p></td><td width="20%"><a href="https://github.com/nswbmw"><img src="https://avatars3.githubusercontent.com/u/4279697?v=3" /></a><p align="center">nswbmw</p></td><td width="20%"><a href="https://github.com/VikramTiwari"><img src="https://avatars0.githubusercontent.com/u/1330677?v=3" /></a><p align="center">VikramTiwari</p></td><td width="20%"><a href="https://github.com/pyros2097"><img src="https://avatars3.githubusercontent.com/u/1687946?v=3" /></a><p align="center">pyros2097</p></td><td width="20%"><a href="https://github.com/mtlima"><img src="https://avatars3.githubusercontent.com/u/9111440?v=3" /></a><p align="center">mtlima</p></td></tr><tr><td width="20%"><a href="https://github.com/bradvogel"><img src="https://avatars2.githubusercontent.com/u/821706?v=3" /></a><p align="center">bradvogel</p></td><td width="20%"><a href="https://github.com/pra85"><img src="https://avatars1.githubusercontent.com/u/829526?v=3" /></a><p align="center">pra85</p></td><td width="20%"><a href="https://github.com/joeledwards"><img src="https://avatars0.githubusercontent.com/u/412853?v=3" /></a><p align="center">joeledwards</p></td><td width="20%"><a href="https://github.com/tempname11"><img src="https://avatars3.githubusercontent.com/u/8409150?v=3" /></a><p align="center">tempname11</p></td></table>
962
965
 
963
966
  # License
964
967
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var Deque = require('double-ended-queue');
3
+ var Deque = require('denque');
4
4
  var debug = require('debug')('ioredis:delayqueue');
5
5
 
6
6
  function DelayQueue() {
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var Promise = require('bluebird');
4
- var Deque = require('double-ended-queue');
4
+ var Deque = require('denque');
5
5
  var Redis = require('../redis');
6
6
  var utils = require('../utils');
7
7
  var util = require('util');
@@ -179,6 +179,7 @@ Cluster.prototype.connect = function () {
179
179
 
180
180
  /**
181
181
  * Called when closed to check whether a reconnection should be made
182
+ *
182
183
  * @private
183
184
  */
184
185
  Cluster.prototype._handleCloseEvent = function () {
@@ -201,7 +202,7 @@ Cluster.prototype._handleCloseEvent = function () {
201
202
 
202
203
  /**
203
204
  * Disconnect from every node in the cluster.
204
- *
205
+ * @param {boolean} [reconnect]
205
206
  * @public
206
207
  */
207
208
  Cluster.prototype.disconnect = function (reconnect) {
@@ -227,7 +228,7 @@ Cluster.prototype.disconnect = function (reconnect) {
227
228
  /**
228
229
  * Quit the cluster gracefully.
229
230
  *
230
- * @param {function} callback
231
+ * @param {function} [callback]
231
232
  * @return {Promise} return 'OK' if successfully
232
233
  * @public
233
234
  */
@@ -28,7 +28,7 @@ SentinelConnector.prototype.check = function (info) {
28
28
  return true;
29
29
  };
30
30
 
31
- SentinelConnector.prototype.connect = function (callback) {
31
+ SentinelConnector.prototype.connect = function (callback, eventEmitter) {
32
32
  this.connecting = true;
33
33
  this.retryAttempts = 0;
34
34
 
@@ -48,20 +48,27 @@ SentinelConnector.prototype.connect = function (callback) {
48
48
  if (_this.currentPoint === _this.sentinels.length) {
49
49
  _this.currentPoint = -1;
50
50
 
51
- var retryDelay;
52
- if (typeof _this.options.sentinelRetryStrategy === 'function') {
53
- retryDelay = _this.options.sentinelRetryStrategy(++_this.retryAttempts);
51
+ var retryDelay = typeof _this.options.sentinelRetryStrategy === 'function'
52
+ ? _this.options.sentinelRetryStrategy(++_this.retryAttempts)
53
+ : null;
54
+
55
+ var errorMsg = typeof retryDelay !== 'number'
56
+ ? 'All sentinels are unreachable and retry is disabled.'
57
+ : 'All sentinels are unreachable. Retrying from scratch after ' + retryDelay + 'ms';
58
+
59
+ if (lastError) {
60
+ errorMsg += ' Last error: ' + lastError.message;
54
61
  }
55
- if (typeof retryDelay !== 'number') {
56
- debug('All sentinels are unreachable and retry is disabled, emitting error...');
57
- var error = 'All sentinels are unreachable.';
58
- if (lastError) {
59
- error += ' Last error: ' + lastError.message;
60
- }
61
- return callback(new Error(error));
62
+
63
+ debug(errorMsg);
64
+
65
+ var error = new Error(errorMsg);
66
+ if (typeof retryDelay === 'number') {
67
+ setTimeout(connectToNext, retryDelay);
68
+ eventEmitter('error', error);
69
+ } else {
70
+ callback(error);
62
71
  }
63
- debug('All sentinels are unreachable. Retrying from scratch after %d', retryDelay);
64
- setTimeout(connectToNext, retryDelay);
65
72
  return;
66
73
  }
67
74
 
@@ -72,15 +79,22 @@ SentinelConnector.prototype.connect = function (callback) {
72
79
  return;
73
80
  }
74
81
  if (resolved) {
82
+ debug('resolved: %s:%s', resolved.host, resolved.port);
75
83
  _this.stream = net.createConnection(resolved);
76
84
  callback(null, _this.stream);
77
- } else if (err) {
78
- debug('failed to connect to sentinel %s:%s because %s', endpoint.host, endpoint.port, err);
79
- lastError = err;
80
- connectToNext();
81
85
  } else {
82
- debug('connected to sentinel %s:%s successfully, but got a invalid reply: %s',
83
- endpoint.host, endpoint.port, resolved);
86
+ var endpointAddress = endpoint.host + ':' + endpoint.port;
87
+ var errorMsg = err
88
+ ? 'failed to connect to sentinel ' + endpointAddress + ' because ' + err.message
89
+ : 'connected to sentinel ' + endpointAddress + ' successfully, but got an invalid reply: ' + resolved;
90
+
91
+ debug(errorMsg);
92
+
93
+ eventEmitter('sentinelError', new Error(errorMsg));
94
+
95
+ if (err) {
96
+ lastError = err;
97
+ }
84
98
  connectToNext();
85
99
  }
86
100
  });
@@ -210,8 +224,9 @@ SentinelConnector.prototype.resolve = function (endpoint, callback) {
210
224
  Redis = require('../redis');
211
225
  }
212
226
  var client = new Redis({
213
- port: endpoint.port,
227
+ port: endpoint.port || 26379,
214
228
  host: endpoint.host,
229
+ family: endpoint.family || this.options.family,
215
230
  retryStrategy: null,
216
231
  enableReadyCheck: false,
217
232
  connectTimeout: this.options.connectTimeout,
@@ -232,7 +247,7 @@ function noop() {}
232
247
 
233
248
  function isSentinelEql(a, b) {
234
249
  return ((a.host || '127.0.0.1') === (b.host || '127.0.0.1')) &&
235
- ((a.port || 6379) === (b.port || 6379));
250
+ ((a.port || 26379) === (b.port || 26379));
236
251
  }
237
252
 
238
253
  module.exports = SentinelConnector;
package/lib/pipeline.js CHANGED
@@ -31,6 +31,12 @@ function Pipeline(redis) {
31
31
  _this.resolve = resolve;
32
32
  _this.reject = reject;
33
33
  });
34
+
35
+ Object.defineProperty(this, 'length', {
36
+ get: function () {
37
+ return _this._queue.length;
38
+ }
39
+ });
34
40
  }
35
41
 
36
42
  _.assign(Pipeline.prototype, Commander.prototype);
@@ -18,7 +18,6 @@ exports.initParser = function () {
18
18
  var _this = this;
19
19
 
20
20
  this.replyParser = new Parser({
21
- name: this.options.parser,
22
21
  stringNumbers: this.options.stringNumbers,
23
22
  returnBuffers: !this.options.dropBufferSupport,
24
23
  returnError: function (err) {
@@ -33,12 +32,6 @@ exports.initParser = function () {
33
32
  _this.disconnect(true);
34
33
  }
35
34
  });
36
-
37
- if (this.replyParser.name === 'hiredis' && !this.options.dropBufferSupport) {
38
- console.warn('[WARN] ioredis is using hiredis parser, however "dropBufferSupport" is disabled. ' +
39
- 'It\'s highly recommended to enable this option. ' +
40
- 'Refer to https://github.com/luin/ioredis/wiki/Improve-Performance for more details.');
41
- }
42
35
  };
43
36
 
44
37
  exports.returnError = function (err) {
package/lib/redis.js CHANGED
@@ -4,7 +4,7 @@ var _ = require('lodash');
4
4
  var util = require('util');
5
5
  var EventEmitter = require('events').EventEmitter;
6
6
  var Promise = require('bluebird');
7
- var Deque = require('double-ended-queue');
7
+ var Deque = require('denque');
8
8
  var Command = require('./command');
9
9
  var Commander = require('./commander');
10
10
  var utils = require('./utils');
@@ -39,11 +39,9 @@ var commands = require('redis-commands');
39
39
  * @param {number} [options.db=0] - Database index to use.
40
40
  * @param {string} [options.password=null] - If set, client will send AUTH command
41
41
  * with the value of this option when connected.
42
- * @param {string} [options.parser=null] - Either "hiredis" or "javascript". If not set, "hiredis" parser
43
- * will be used if it's installed (`npm install hiredis`), otherwise "javascript" parser will be used.
44
42
  * @param {boolean} [options.dropBufferSupport=false] - Drop the buffer support for better performance.
45
- * This option is recommended to be enabled when "hiredis" parser is used.
46
- * Refer to https://github.com/luin/ioredis/wiki/Improve-Performance for more details.
43
+ * This option is recommended to be enabled when
44
+ * handling large array response and you don't need the buffer support.
47
45
  * @param {boolean} [options.enableReadyCheck=true] - When a connection is established to
48
46
  * the Redis server, the server might still be loading the database from disk.
49
47
  * While loading, the server not respond to any commands.
@@ -84,8 +82,6 @@ var commands = require('redis-commands');
84
82
  * Only available for cluster mode.
85
83
  * @param {boolean} [options.stringNumbers=false] - Force numbers to be always returned as JavaScript
86
84
  * strings. This option is necessary when dealing with big numbers (exceed the [-2^53, +2^53] range).
87
- * Notice that when this option is enabled, the JavaScript parser will be used even "hiredis" is specified
88
- * because only JavaScript parser supports this feature for the time being.
89
85
  * @extends [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)
90
86
  * @extends Commander
91
87
  * @example
@@ -109,11 +105,11 @@ function Redis() {
109
105
  return new Redis(arguments[0], arguments[1], arguments[2]);
110
106
  }
111
107
 
108
+ this.parseOptions(arguments[0], arguments[1], arguments[2]);
109
+
112
110
  EventEmitter.call(this);
113
111
  Commander.call(this);
114
112
 
115
- this.parseOptions(arguments[0], arguments[1], arguments[2]);
116
-
117
113
  this.resetCommandQueue();
118
114
  this.resetOfflineQueue();
119
115
 
@@ -156,9 +152,9 @@ Redis.defaultOptions = {
156
152
  port: 6379,
157
153
  host: 'localhost',
158
154
  family: 4,
159
- connectTimeout: 3000,
155
+ connectTimeout: 10000,
160
156
  retryStrategy: function (times) {
161
- return Math.min(times * 2, 2000);
157
+ return Math.min(times * 50, 2000);
162
158
  },
163
159
  keepAlive: 0,
164
160
  noDelay: true,
@@ -174,7 +170,6 @@ Redis.defaultOptions = {
174
170
  password: null,
175
171
  db: 0,
176
172
  // Others
177
- parser: null,
178
173
  dropBufferSupport: false,
179
174
  enableOfflineQueue: true,
180
175
  enableReadyCheck: true,
@@ -220,6 +215,9 @@ Redis.prototype.parseOptions = function () {
220
215
  if (typeof this.options.db === 'string') {
221
216
  this.options.db = parseInt(this.options.db, 10);
222
217
  }
218
+ if (this.options.parser === 'hiredis') {
219
+ console.warn('Hiredis parser is abandoned in ioredis v3.0, and JavaScript parser will be used');
220
+ }
223
221
  };
224
222
 
225
223
  /**
@@ -244,7 +242,7 @@ Redis.prototype.setStatus = function (status, arg) {
244
242
  /**
245
243
  * Create a connection to Redis.
246
244
  * This method will be invoked automatically when creating a new Redis instance.
247
- * @param {function} callback
245
+ * @param {function} [callback]
248
246
  * @return {Promise}
249
247
  * @public
250
248
  */
@@ -313,6 +311,8 @@ Redis.prototype.connect = function (callback) {
313
311
  };
314
312
  _this.once(CONNECT_EVENT, connectionConnectHandler);
315
313
  _this.once('close', connectionCloseHandler);
314
+ }, function (type, err) {
315
+ _this.silentEmit(type, err);
316
316
  });
317
317
  }.bind(this)).nodeify(callback);
318
318
  };
@@ -46,9 +46,12 @@ exports.convertBufferToString = function (value, encoding) {
46
46
  return value.toString(encoding);
47
47
  }
48
48
  if (Array.isArray(value)) {
49
- var res = [];
50
- for (var i = 0; i < value.length; ++i) {
51
- res[i] = exports.convertBufferToString(value[i], encoding);
49
+ var length = value.length;
50
+ var res = Array(length);
51
+ for (var i = 0; i < length; ++i) {
52
+ res[i] = value[i] instanceof Buffer && encoding === 'utf8'
53
+ ? value[i].toString()
54
+ : exports.convertBufferToString(value[i], encoding);
52
55
  }
53
56
  return res;
54
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ioredis",
3
- "version": "2.5.0",
3
+ "version": "3.0.0",
4
4
  "description": "A delightful, performance-focused Redis client for Node and io.js",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -29,21 +29,21 @@
29
29
  "bluebird": "^3.3.4",
30
30
  "cluster-key-slot": "^1.0.6",
31
31
  "debug": "^2.2.0",
32
- "double-ended-queue": "^2.1.0-0",
32
+ "denque": "^1.1.0",
33
33
  "flexbuffer": "0.0.6",
34
34
  "lodash": "^4.8.2",
35
35
  "redis-commands": "^1.2.0",
36
- "redis-parser": "^1.3.0"
36
+ "redis-parser": "^2.4.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "chai": "^3.5.0",
40
- "codeclimate-test-reporter": "0.3.1",
40
+ "codeclimate-test-reporter": "0.4.0",
41
41
  "cz-conventional-changelog": "^1.1.5",
42
42
  "istanbul": "^0.4.2",
43
43
  "jsdoc": "^3.4.0",
44
- "jsdoc-to-markdown": "^1.3.3",
44
+ "jsdoc-to-markdown": "^2.0.0",
45
45
  "matcha": "^0.7.0",
46
- "mocha": "^2.4.5",
46
+ "mocha": "^3.1.1",
47
47
  "redis": "^2.4.2",
48
48
  "server-destroy": "^1.0.1",
49
49
  "sinon": "^1.17.3"