Browse Source

Minor hiredis handling improvement

internal
Ruben Bridgewater 9 years ago
parent
commit
bc85c4a01d
  1. 2
      index.js
  2. 29
      lib/parsers/hiredis.js

2
index.js

@ -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
// 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.
// That way the result / error won't stay in a try catch block and catch user things
this.reply_parser.send_error = function (data) {

29
lib/parsers/hiredis.js

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

Loading…
Cancel
Save