Skip to content

Commit a757cda

Browse files
Force reconnection when new master is available
1 parent d223c9c commit a757cda

File tree

2 files changed

+7
-42
lines changed

2 files changed

+7
-42
lines changed

index.js

+6
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,12 @@ RedisClient.prototype.connection_gone = function (why) {
467467
}, this.retry_delay);
468468
};
469469

470+
RedisClient.prototype.forceReconnectionAttempt = function (){
471+
clearTimeout(this.retry_timer);
472+
this.initialize_retry_vars();
473+
this.connection_gone();
474+
};
475+
470476
RedisClient.prototype.on_data = function (data) {
471477
if (exports.debug_mode) {
472478
console.log("net read " + this.host + ":" + this.port + " id " + this.connection_id + ": " + data.toString());

sentinel.js

+1-42
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ function RedisMetaClient(masterName, startingSentinels) {
4343
}
4444
}
4545
self.messagesReceived = newLastMessages;
46-
47-
48-
console.log(self.masterClients.length);
4946
}, 2000);
5047

5148
this.getSentinels(startingSentinels, function(error, sentinelsConfig) {
@@ -68,7 +65,6 @@ function RedisMetaClient(masterName, startingSentinels) {
6865
this.on('sentinelsConfigured', function() {
6966
self.sentinelsConfigured();
7067
});
71-
7268
}
7369

7470
util.inherits(RedisMetaClient, events.EventEmitter);
@@ -455,6 +451,7 @@ RedisMetaClient.prototype.masterAvailable = function(availableMaster) {
455451
this.masterClients.forEach(function(masterClient){
456452
masterClient.client.host = availableMaster.host;
457453
masterClient.client.port = availableMaster.port;
454+
masterClient.client.forceReconnectionAttempt();
458455
});
459456

460457
this.emit('healthyChange', true);
@@ -477,42 +474,4 @@ RedisMetaClient.prototype.createMasterClient = function(options) {
477474
return client;
478475
};
479476

480-
// RedisMetaClient.prototype.getMasterClient = function(options, cb) {
481-
482-
// if(this.healthy){
483-
// return RedisSingleClient.createClient(this.master.port, this.master.host, options);
484-
// }
485-
// else {
486-
// var client = {};
487-
// for (var i in RedisSingleClient.RedisClient.prototype) {
488-
// console.log(i);
489-
490-
// }
491-
// }
492-
// // for (var i in RedisSingleClient.RedisClient.prototype) {
493-
// // console.log(i);
494-
// // if(healthy){
495-
496-
// // }
497-
// // else {
498-
499-
// // }
500-
// // }
501-
// // if(this.healthy && this.masterClient) {
502-
// // return cb(null, this.masterClient);
503-
// // } else {
504-
// // if(this.healthy && !this.masterClient){
505-
// // console.log("this.masterClient not available");
506-
// // }
507-
// // return cb("Unhealthy");
508-
// // }
509-
// // console.log(this.healthy);
510-
// // console.log(this.master.port);
511-
// // if(this.masterClient) {
512-
// // return this.masterClient;
513-
// // } else {
514-
// // return false;
515-
// // }
516-
// };
517-
518477
exports.RedisMetaClient = RedisMetaClient;

0 commit comments

Comments
 (0)