From a89adfc80259a70f5b379db967e231f9b26ae211 Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Sat, 5 Dec 2015 13:56:20 +0800 Subject: [PATCH] Emits "error" when connection is down for `scanStream`. Close #199 --- Changelog.md | 3 +++ README.md | 2 +- lib/scan_stream.js | 6 +++++- test/functional/scan_stream.js | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 68cefd37..29fdc550 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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)). diff --git a/README.md b/README.md index ed0908ae..1d5ba140 100644 --- a/README.md +++ b/README.md @@ -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 -

luin

dguo

nakulgan

hayeah

albin3

phlip9

fracmak

suprememoocow

lpinca

devaos

jeffjen

horx

ColmHally

klinquist

alsotang

pensierinmusica

devoto13

igrcic

henstock

VikramTiwari

i5ting

nswbmw

pyros2097

mtlima

joeledwards

ArtskydJ

tkalfigo

AVVS

+

luin

dguo

nakulgan

hayeah

shaharmor

albin3

phlip9

fracmak

suprememoocow

lpinca

devaos

jeffjen

horx

klinquist

ColmHally

alsotang

zhuangya

pensierinmusica

VikramTiwari

igrcic

nswbmw

pyros2097

henstock

i5ting

mtlima

devoto13

joeledwards

ArtskydJ

tkalfigo

AVVS

# Roadmap diff --git a/lib/scan_stream.js b/lib/scan_stream.js index 9041b4f2..ffcbed80 100644 --- a/lib/scan_stream.js +++ b/lib/scan_stream.js @@ -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; diff --git a/test/functional/scan_stream.js b/test/functional/scan_stream.js index 3836ec14..c33529ce 100644 --- a/test/functional/scan_stream.js +++ b/test/functional/scan_stream.js @@ -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 () {