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

Minor hiredis handling improvement

This commit is contained in:
Ruben Bridgewater
2015-11-22 17:02:18 +01:00
parent 634dcee859
commit bc85c4a01d
2 changed files with 16 additions and 21 deletions

View File

@@ -293,7 +293,7 @@ RedisClient.prototype.init_parser = function () {
// return_buffers sends back Buffers from parser to callback. detect_buffers sends back Buffers from parser, but // return_buffers sends back Buffers from parser to callback. detect_buffers sends back Buffers from parser, but
// converts to Strings if the input arguments are not Buffers. // converts to Strings if the input arguments are not Buffers.
this.reply_parser = new this.parser_module.Parser(self.options.return_buffers || self.options.detect_buffers || false); this.reply_parser = new this.parser_module.Parser(self.options.return_buffers || self.options.detect_buffers);
// Important: Only send results / errors async. // Important: Only send results / errors async.
// That way the result / error won't stay in a try catch block and catch user things // That way the result / error won't stay in a try catch block and catch user things
this.reply_parser.send_error = function (data) { this.reply_parser.send_error = function (data) {

View File

@@ -4,37 +4,32 @@ var hiredis = require('hiredis');
function HiredisReplyParser(return_buffers) { function HiredisReplyParser(return_buffers) {
this.name = exports.name; this.name = exports.name;
this.return_buffers = return_buffers; this.reader = new hiredis.Reader({
this.reset(); return_buffers: return_buffers
});
} }
HiredisReplyParser.prototype.reset = function () { HiredisReplyParser.prototype.return_data = function () {
this.reader = new hiredis.Reader({ try {
return_buffers: this.return_buffers || false return this.reader.get();
}); } catch (err) {
// Protocol errors land here
this.send_error(err);
return void 0;
}
}; };
HiredisReplyParser.prototype.execute = function (data) { HiredisReplyParser.prototype.execute = function (data) {
var reply;
this.reader.feed(data); this.reader.feed(data);
while (true) { var reply = this.return_data();
try {
reply = this.reader.get();
} catch (err) {
// Protocol errors land here
this.send_error(err);
break;
}
if (reply === undefined) { while (reply !== undefined) {
break; if (reply && reply.name === 'Error') {
}
if (reply && reply.constructor === Error) {
this.send_error(reply); this.send_error(reply);
} else { } else {
this.send_reply(reply); this.send_reply(reply);
} }
reply = this.return_data();
} }
}; };