File tree 5 files changed +18
-4
lines changed
5 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ function Cluster(startupNodes, options) {
57
57
58
58
var _this = this ;
59
59
this . connectionPool . on ( '-node' , function ( redis ) {
60
- if ( _this . subscriber === redis ) {
60
+ if ( _this . status !== 'disconnecting' && _this . subscriber === redis ) {
61
61
_this . selectSubscriber ( ) ;
62
62
}
63
63
_this . emit ( '-node' , redis ) ;
@@ -193,6 +193,8 @@ Cluster.prototype.connect = function () {
193
193
* @public
194
194
*/
195
195
Cluster . prototype . disconnect = function ( reconnect ) {
196
+ this . setStatus ( 'disconnecting' ) ;
197
+
196
198
if ( ! reconnect ) {
197
199
this . manuallyClosing = true ;
198
200
}
Original file line number Diff line number Diff line change @@ -307,7 +307,11 @@ Redis.prototype.disconnect = function (reconnect) {
307
307
clearTimeout ( this . reconnectTimeout ) ;
308
308
this . reconnectTimeout = null ;
309
309
}
310
- this . connector . disconnect ( ) ;
310
+ if ( this . status === 'wait' ) {
311
+ eventHandler . closeHandler ( this ) ( ) ;
312
+ } else {
313
+ this . connector . disconnect ( ) ;
314
+ }
311
315
} ;
312
316
313
317
/**
Original file line number Diff line number Diff line change 5
5
"main" : " index.js" ,
6
6
"scripts" : {
7
7
"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" ,
9
9
"generate-docs" : " jsdoc2md lib/redis.js lib/cluster/index.js lib/commander.js > API.md" ,
10
10
"build" : " node tools/build > commands.js" ,
11
11
"bench" : " matcha benchmarks/*.js"
Original file line number Diff line number Diff line change @@ -1219,7 +1219,7 @@ describe('cluster', function () {
1219
1219
expect ( cluster . nodes ( 'master' ) ) . to . have . lengthOf ( 2 ) ;
1220
1220
expect ( cluster . nodes ( 'slave' ) ) . to . have . lengthOf ( 1 ) ;
1221
1221
1222
- cluster . on ( '-node' , function ( ) {
1222
+ cluster . once ( '-node' , function ( ) {
1223
1223
expect ( cluster . nodes ( ) ) . to . have . lengthOf ( 2 ) ;
1224
1224
expect ( cluster . nodes ( 'all' ) ) . to . have . lengthOf ( 2 ) ;
1225
1225
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 () {
26
26
} ) ;
27
27
} ) ;
28
28
} ) ;
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
+ } ) ;
29
37
} ) ;
You can’t perform that action at this time.
0 commit comments