1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

Support for multiple reply parsers including hiredis.

Several parsing bugs fixed in JavaScript.
Some new config options that need to be better documented.
This commit is contained in:
Matt Ranney
2010-12-06 09:11:16 -08:00
parent 232f34a4e1
commit b907364573
10 changed files with 172 additions and 152 deletions

View File

@@ -1,11 +1,15 @@
/*global Buffer require exports console setTimeout */
var events = require("events"),
util = require("../util").util,
hiredis = require("hiredis");
exports.debug_mode = false;
exports.name = "hiredis";
function HiredisReplyParser(options) {
this.name = exports.name;
this.options = options || {};
this.return_buffers = this.options.return_buffers;
if (this.return_buffers == undefined) this.return_buffers = true;
this.reset();
events.EventEmitter.call(this);
}
@@ -13,26 +17,25 @@ function HiredisReplyParser(options) {
util.inherits(HiredisReplyParser, events.EventEmitter);
exports.Parser = HiredisReplyParser;
exports.debug_mode = false;
exports.type = "hiredis";
HiredisReplyParser.prototype.reset = function() {
this.reader = new hiredis.Reader({ return_buffers: this.return_buffers });
}
HiredisReplyParser.prototype.reset = function () {
this.reader = new hiredis.Reader({
return_buffers: this.options.return_buffers || false
});
};
HiredisReplyParser.prototype.execute = function(data) {
HiredisReplyParser.prototype.execute = function (data) {
var reply;
this.reader.feed(data);
try {
while ((reply = this.reader.get()) !== undefined) {
if (reply && reply.constructor == Error) {
if (reply && reply.constructor === Error) {
this.emit("reply error", reply);
} else {
this.emit("reply", reply);
}
}
} catch(err) {
} catch (err) {
this.emit("error", err);
}
}
};