Skip to content
Browse files

Now we dont crash if all redises disappear

  • Loading branch information...
1 parent 8c8c0ad commit 5abc42345f06f0a915a6237ef59a895b92dfb9f4 @sreeix committed Mar 12, 2013
Showing with 14 additions and 10 deletions.
  1. +11 −4 lib/redis_proxy.js
  2. +2 −6 lib/server.js
  3. +1 −0 server.js
View
15 lib/redis_proxy.js
@@ -80,7 +80,7 @@ RedisProxy.prototype.nextActive = function() {
this.readyup(this.active);
logger.info("Setting up as active "+ this.active.options.host +" : " + this.active.options.port);
} else {
- throw new Error("Expected to have atleast one redis to proxy");
+ logger.error("No redis available");
}
};
@@ -90,17 +90,24 @@ Object.defineProperty(RedisProxy.prototype, 'active', {
// balancing strategies
RedisProxy.prototype.readsToSlaves = function(command, id, callback) {
+ if(!this.active){
+ return callback(new Error("Expected to have atleast one redis to proxy"));
+ }
if(redisCommand.readOnly(command)) {
logger.info('Read only command sending to the slave');
(this.nextSlave() || this._active).sendCommand(command, id, callback);
} else {
logger.info('mutating command sending to the active master');
- this._active.sendCommand(command, id, callback);
+ this.active.sendCommand(command, id, callback);
}
};
RedisProxy.prototype.allToMaster = function(command, id, callback) {
- this._active.sendCommand(command, id, callback);
+ if(this._active){
+ this._active.sendCommand(command, id, callback);
+ }else{
+ return callback(new Error("Expected to have atleast one redis to proxy"));
+ }
};
RedisProxy.prototype.nextSlave = function() {
@@ -110,7 +117,7 @@ RedisProxy.prototype.nextSlave = function() {
};
RedisProxy.prototype.quit = function(id) {
- return this.active.close(id);
+ if(this.active) this.active.close(id);
};
RedisProxy.prototype.watch = function(){
View
8 lib/server.js
@@ -160,13 +160,9 @@ Server.prototype._clearConnections = function clearConnections(){
};
Object.defineProperty(Server.prototype, 'host', {
- get: function() {
- return this.options.host;
- }
+ get: function() {return this.options.host;}
});
Object.defineProperty(Server.prototype, 'port', {
- get: function() {
- return this.options.port;
- }
+ get: function() {return this.options.port;}
});
View
1 server.js
@@ -30,6 +30,7 @@ var server = net.createServer(function (socket) {
redis_proxy.sendCommand(command, id, function(err, res) {
if(err){
logger.error(err);
+ return socket.write("+ERR "+ err+"\r\n");
}
if(res){
socket.write(res.toString('utf8'));

0 comments on commit 5abc423

Please sign in to comment.
Something went wrong with that request. Please try again.