From 34ed2c56431c63136fdf601e1c94acf4ff338379 Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Thu, 26 Nov 2015 00:07:07 +0800 Subject: [PATCH] Emits "error" when all sentinels are unreachable. Close #200 --- Changelog.md | 2 ++ lib/redis.js | 1 + test/functional/sentinel.js | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index c63de074..95105d82 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,8 @@ This file is a manually maintained list of changes for each release. Feel free t ## Master Branch (Unreleased) +* [Sentinel] Emits "error" when all sentinels are unreachable ([#200](https://github.com/luin/ioredis/issues/200)). + ## v1.11.0 - November 19, 2015 * Emits "select" event when the database changed. diff --git a/lib/redis.js b/lib/redis.js index e173dcd5..eda5f0c6 100644 --- a/lib/redis.js +++ b/lib/redis.js @@ -259,6 +259,7 @@ Redis.prototype.connect = function (callback) { this.connector.connect(function (err, stream) { if (err) { _this.flushQueue(err); + _this.silentEmit('error', err); reject(err); return; } diff --git a/test/functional/sentinel.js b/test/functional/sentinel.js index 6393ae1d..8bf690ac 100644 --- a/test/functional/sentinel.js +++ b/test/functional/sentinel.js @@ -65,10 +65,22 @@ describe('sentinel', function () { }); redis.get('foo', function (error) { + finish(); expect(error.message).to.match(/are unreachable/); - redis.disconnect(); - done(); }); + + redis.on('error', function (error) { + expect(error.message).to.match(/are unreachable/); + finish(); + }); + + var pending = 2; + function finish() { + if (!--pending) { + redis.disconnect(); + done(); + } + } }); it('should close the connection to the sentinel when resolving successfully', function (done) {