1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Fix bug where subscribe commands would not handle redis-server startup error properly.

This commit is contained in:
Matt Ranney
2011-01-18 13:56:53 -08:00
parent fc5968c96c
commit c1b5587e74
3 changed files with 18 additions and 10 deletions

View File

@@ -1,6 +1,10 @@
Changelog Changelog
========= =========
## v0.5.1 - January 18, 2011
Fix bug where subscribe commands would not handle redis-server startup error properly.
## v0.5.0 - December 29, 2010 ## v0.5.0 - December 29, 2010
Some bug fixes: Some bug fixes:

View File

@@ -191,7 +191,7 @@ RedisClient.prototype.connection_gone = function (why) {
} }
if (exports.debug_mode) { if (exports.debug_mode) {
console.log("Retry conneciton in " + self.retry_delay + " ms"); console.log("Retry connection in " + self.retry_delay + " ms");
} }
self.attempts += 1; self.attempts += 1;
self.emit("reconnecting", { self.emit("reconnecting", {
@@ -210,7 +210,7 @@ RedisClient.prototype.connection_gone = function (why) {
RedisClient.prototype.on_data = function (data) { RedisClient.prototype.on_data = function (data) {
if (exports.debug_mode) { if (exports.debug_mode) {
console.log("on_data: " + data.toString()); console.log("net read fd " + this.stream.fd + ": " + data.toString());
} }
try { try {
@@ -241,7 +241,7 @@ RedisClient.prototype.return_error = function (err) {
}); });
} }
} else { } else {
console.log("node_redis: no callback to send error: " + util.inspect(err)); console.log("node_redis: no callback to send error: " + err.message);
// this will probably not make it anywhere useful, but we might as well throw // this will probably not make it anywhere useful, but we might as well throw
throw err; throw err;
} }
@@ -255,7 +255,7 @@ RedisClient.prototype.return_reply = function (reply) {
this.emit("idle"); this.emit("idle");
} }
if (command_obj) { if (command_obj && !command_obj.sub_command) {
if (typeof command_obj.callback === "function") { if (typeof command_obj.callback === "function") {
// HGETALL special case replies with keyed Buffers // HGETALL special case replies with keyed Buffers
if (reply && 'hgetall' === command_obj.command.toLowerCase()) { if (reply && 'hgetall' === command_obj.command.toLowerCase()) {
@@ -301,6 +301,8 @@ RedisClient.prototype.return_reply = function (reply) {
} else { } else {
throw new Error("subscriptions are active but got an invalid reply: " + reply); throw new Error("subscriptions are active but got an invalid reply: " + reply);
} }
} else {
throw new Error("node_redis command queue state error. If you can reproduce this, please report it.");
} }
}; };
@@ -336,7 +338,8 @@ RedisClient.prototype.send_command = function () {
command_obj = { command_obj = {
command: command, command: command,
args: args, args: args,
callback: callback callback: callback,
sub_command: false
}; };
if (! this.connected) { if (! this.connected) {
@@ -351,6 +354,7 @@ RedisClient.prototype.send_command = function () {
if (this.subscriptions === false && exports.debug_mode) { if (this.subscriptions === false && exports.debug_mode) {
console.log("Entering pub/sub mode from " + command); console.log("Entering pub/sub mode from " + command);
} }
command_obj.sub_command = true;
this.subscriptions = true; this.subscriptions = true;
} else { } else {
if (command === "quit") { if (command === "quit") {
@@ -358,22 +362,22 @@ RedisClient.prototype.send_command = function () {
} else if (this.subscriptions === true) { } else if (this.subscriptions === true) {
throw new Error("Connection in pub/sub mode, only pub/sub commands may be used"); throw new Error("Connection in pub/sub mode, only pub/sub commands may be used");
} }
this.command_queue.push(command_obj);
} }
this.command_queue.push(command_obj);
this.commands_sent += 1; this.commands_sent += 1;
elem_count = 1; elem_count = 1;
buffer_args = false; buffer_args = false;
elem_count += args.length; elem_count += args.length;
// Probably should just scan this like a normal person // Probably should just scan this like a normal person. This is clever, but might be slow.
buffer_args = args.some(function (arg) { buffer_args = args.some(function (arg) {
// this is clever, but might be slow
return arg instanceof Buffer; return arg instanceof Buffer;
}); });
// Always use "Multi bulk commands", but if passed any Buffer args, then do multiple writes, one for each arg // Always use "Multi bulk commands", but if passed any Buffer args, then do multiple writes, one for each arg
// This means that using Buffers in commands is going to be slower, so use Strings if you don't already have a Buffer. // This means that using Buffers in commands is going to be slower, so use Strings if you don't already have a Buffer.
// Also, why am I putting user documentation in the library source code?
command_str = "*" + elem_count + "\r\n$" + command.length + "\r\n" + command + "\r\n"; command_str = "*" + elem_count + "\r\n$" + command.length + "\r\n" + command + "\r\n";
@@ -391,7 +395,7 @@ RedisClient.prototype.send_command = function () {
command_str += "$" + Buffer.byteLength(arg) + "\r\n" + arg + "\r\n"; command_str += "$" + Buffer.byteLength(arg) + "\r\n" + arg + "\r\n";
} }
if (exports.debug_mode) { if (exports.debug_mode) {
console.log("send command: " + command_str); console.log("send fd " + this.stream.fd + ": " + command_str);
} }
stream.write(command_str); stream.write(command_str);
} else { } else {

View File

@@ -1,5 +1,5 @@
{ "name" : "redis", { "name" : "redis",
"version" : "0.5.0", "version" : "0.5.1",
"description" : "Redis client library", "description" : "Redis client library",
"author": "Matt Ranney <mjr@ranney.com>", "author": "Matt Ranney <mjr@ranney.com>",
"contributors": [ "contributors": [