You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
have the parser try to recover from errors when it has them and communicate this back to the user
This commit is contained in:
16
index.js
16
index.js
@@ -9,10 +9,7 @@ var net = require("net"),
|
|||||||
exports.debug_mode = false;
|
exports.debug_mode = false;
|
||||||
|
|
||||||
function RedisReplyParser() {
|
function RedisReplyParser() {
|
||||||
this.state = "type";
|
this.reset();
|
||||||
this.return_buffer = new Buffer(16384); // for holding replies, might grow
|
|
||||||
this.tmp_buffer = new Buffer(128); // for holding size fields
|
|
||||||
|
|
||||||
events.EventEmitter.call(this);
|
events.EventEmitter.call(this);
|
||||||
}
|
}
|
||||||
sys.inherits(RedisReplyParser, events.EventEmitter);
|
sys.inherits(RedisReplyParser, events.EventEmitter);
|
||||||
@@ -38,6 +35,12 @@ function to_array(args) {
|
|||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RedisReplyParser.prototype.reset = function() {
|
||||||
|
this.state = "type";
|
||||||
|
this.return_buffer = new Buffer(16384); // for holding replies, might grow
|
||||||
|
this.tmp_buffer = new Buffer(128); // for holding size fields
|
||||||
|
}
|
||||||
|
|
||||||
RedisReplyParser.prototype.execute = function (incoming_buf) {
|
RedisReplyParser.prototype.execute = function (incoming_buf) {
|
||||||
var pos = 0, bd_tmp, bd_str, i;
|
var pos = 0, bd_tmp, bd_str, i;
|
||||||
//, state_times = {}, start_execute = new Date(), start_switch, end_switch, old_state;
|
//, state_times = {}, start_execute = new Date(), start_switch, end_switch, old_state;
|
||||||
@@ -348,7 +351,7 @@ function RedisClient(stream) {
|
|||||||
self.return_reply(reply);
|
self.return_reply(reply);
|
||||||
});
|
});
|
||||||
self.reply_parser.on("error", function (err) {
|
self.reply_parser.on("error", function (err) {
|
||||||
console.log("Redis reply parser error: " + err.stack);
|
self.emit("error", new Error("Redis reply parser error: " + err.stack));
|
||||||
});
|
});
|
||||||
|
|
||||||
self.retry_timer = null;
|
self.retry_timer = null;
|
||||||
@@ -454,7 +457,8 @@ RedisClient.prototype.on_data = function (data) {
|
|||||||
try {
|
try {
|
||||||
this.reply_parser.execute(data);
|
this.reply_parser.execute(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Exception in RedisReplyParser: " + err.stack);
|
this.reply_parser.reset(); // the parser has state - must reset it or it can never recover
|
||||||
|
this.emit("error", err); // pass the error along
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user