File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ function Cluster(startupNodes, options) {
5757
5858 var _this = this ;
5959 this . connectionPool . on ( '-node' , function ( redis ) {
60- if ( _this . subscriber === redis ) {
60+ if ( _this . status !== 'disconnecting' && _this . subscriber === redis ) {
6161 _this . selectSubscriber ( ) ;
6262 }
6363 _this . emit ( '-node' , redis ) ;
@@ -193,6 +193,8 @@ Cluster.prototype.connect = function () {
193193 * @public
194194 */
195195Cluster . prototype . disconnect = function ( reconnect ) {
196+ this . setStatus ( 'disconnecting' ) ;
197+
196198 if ( ! reconnect ) {
197199 this . manuallyClosing = true ;
198200 }
Original file line number Diff line number Diff line change @@ -307,7 +307,11 @@ Redis.prototype.disconnect = function (reconnect) {
307307 clearTimeout ( this . reconnectTimeout ) ;
308308 this . reconnectTimeout = null ;
309309 }
310- this . connector . disconnect ( ) ;
310+ if ( this . status === 'wait' ) {
311+ eventHandler . closeHandler ( this ) ( ) ;
312+ } else {
313+ this . connector . disconnect ( ) ;
314+ }
311315} ;
312316
313317/**
Original file line number Diff line number Diff line change 55 "main" : " index.js" ,
66 "scripts" : {
77 "test" : " NODE_ENV=test mocha" ,
8- "test:cov" : " NODE_ENV=test DEBUG=ioredis:* node ./node_modules/istanbul/lib/cli.js cover --preserve-comments ./node_modules/mocha/bin/_mocha -- -R spec" ,
8+ "test:cov" : " NODE_ENV=test node ./node_modules/istanbul/lib/cli.js cover --preserve-comments ./node_modules/mocha/bin/_mocha -- -R spec" ,
99 "generate-docs" : " jsdoc2md lib/redis.js lib/cluster/index.js lib/commander.js > API.md" ,
1010 "build" : " node tools/build > commands.js" ,
1111 "bench" : " matcha benchmarks/*.js"
Original file line number Diff line number Diff line change @@ -1219,7 +1219,7 @@ describe('cluster', function () {
12191219 expect ( cluster . nodes ( 'master' ) ) . to . have . lengthOf ( 2 ) ;
12201220 expect ( cluster . nodes ( 'slave' ) ) . to . have . lengthOf ( 1 ) ;
12211221
1222- cluster . on ( '-node' , function ( ) {
1222+ cluster . once ( '-node' , function ( ) {
12231223 expect ( cluster . nodes ( ) ) . to . have . lengthOf ( 2 ) ;
12241224 expect ( cluster . nodes ( 'all' ) ) . to . have . lengthOf ( 2 ) ;
12251225 expect ( cluster . nodes ( 'master' ) ) . to . have . lengthOf ( 1 ) ;
Original file line number Diff line number Diff line change @@ -26,4 +26,12 @@ describe('lazy connect', function () {
2626 } ) ;
2727 } ) ;
2828 } ) ;
29+
30+ it ( 'should be able to disconnect' , function ( done ) {
31+ var redis = new Redis ( { lazyConnect : true } ) ;
32+ redis . on ( 'end' , function ( ) {
33+ done ( ) ;
34+ } ) ;
35+ redis . disconnect ( ) ;
36+ } ) ;
2937} ) ;
You can’t perform that action at this time.
0 commit comments