Skip to content

Commit

Permalink
Emits "error" when connection is down for scanStream. Close #199
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Dec 5, 2015
1 parent f7d80fc commit a89adfc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This file is a manually maintained list of changes for each release. Feel free t

## Master Branch (Unreleased)

* [Cluster] Add queue support for failover and CLUSTERDOWN handling. [Shahar Mor](https://github.com/shaharmor).
* Emits "error" when connection is down for `scanStream` ([#199](https://github.com/luin/ioredis/issues/199)).

## v1.11.1 - November 26, 2015

* [Sentinel] Emits "error" when all sentinels are unreachable ([#200](https://github.com/luin/ioredis/issues/200)).
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ I'm happy to receive bug reports, fixes, documentation enhancements, and any oth
And since I'm not a native English speaker, if you find any grammar mistakes in the documentation, please also let me know. :)

# Contributors
<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/nakulgan"><img src="https://avatars.githubusercontent.com/u/189836?v=3" /></a><p align="center">nakulgan</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></tr><tr><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><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/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/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/devaos"><img src="https://avatars.githubusercontent.com/u/5412167?v=3" /></a><p align="center">devaos</p></td></tr><tr><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/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/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/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/igrcic"><img src="https://avatars.githubusercontent.com/u/394398?v=3" /></a><p align="center">igrcic</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/VikramTiwari"><img src="https://avatars.githubusercontent.com/u/1330677?v=3" /></a><p align="center">VikramTiwari</p></td></tr><tr><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/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/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/joeledwards"><img src="https://avatars.githubusercontent.com/u/412853?v=3" /></a><p align="center">joeledwards</p></td></tr><tr><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><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/AVVS"><img src="https://avatars.githubusercontent.com/u/1713617?v=3" /></a><p align="center">AVVS</p></td></table>
<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/nakulgan"><img src="https://avatars.githubusercontent.com/u/189836?v=3" /></a><p align="center">nakulgan</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/shaharmor"><img src="https://avatars.githubusercontent.com/u/10861920?v=3" /></a><p align="center">shaharmor</p></td></tr><tr><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><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/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/lpinca"><img src="https://avatars.githubusercontent.com/u/1443911?v=3" /></a><p align="center">lpinca</p></td></tr><tr><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/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/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/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/ColmHally"><img src="https://avatars.githubusercontent.com/u/20333?v=3" /></a><p align="center">ColmHally</p></td></tr><tr><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><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/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/VikramTiwari"><img src="https://avatars.githubusercontent.com/u/1330677?v=3" /></a><p align="center">VikramTiwari</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/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/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/mtlima"><img src="https://avatars.githubusercontent.com/u/9111440?v=3" /></a><p align="center">mtlima</p></td></tr><tr><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/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/ArtskydJ"><img src="https://avatars.githubusercontent.com/u/1833684?v=3" /></a><p align="center">ArtskydJ</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/AVVS"><img src="https://avatars.githubusercontent.com/u/1713617?v=3" /></a><p align="center">AVVS</p></td></tr></table>

# Roadmap

Expand Down
6 changes: 5 additions & 1 deletion lib/scan_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ ScanStream.prototype._read = function () {
args.push('COUNT', this.opt.count);
}
var _this = this;
this.opt.redis[this.opt.command](args, function (_, res) {
this.opt.redis[this.opt.command](args, function (err, res) {
if (err) {
_this.emit('error', err);
return;
}
_this._redisCursor = (res[0] instanceof Buffer) ? res[0].toString() : res[0];
if (_this._redisCursor === '0') {
_this._redisDrained = true;
Expand Down
16 changes: 16 additions & 0 deletions test/functional/scan_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ describe('*scanStream', function () {
});
});
});

it('should emit an error when connection is down', function (done) {
var keys = [];
var redis = new Redis();
redis.mset('foo1', 1, 'foo2', 1, 'foo3', 1, 'foo4', 1, 'foo10', 1, function () {
redis.disconnect();
var stream = redis.scanStream({ count: 1 });
stream.on('data', function (data) {
keys = keys.concat(data);
});
stream.on('error', function (err) {
expect(err.message).to.eql('Connection is closed.');
done();
});
});
});
});

describe('scanBufferStream', function () {
Expand Down

0 comments on commit a89adfc

Please sign in to comment.