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

Try to use hiredis as default reply parser

This commit is contained in:
Pieter Noordhuis
2010-11-30 22:40:09 +01:00
parent 1e698e3fce
commit 4bef57cff0
2 changed files with 46 additions and 1 deletions

35
lib/parser/hiredis.js Normal file
View File

@@ -0,0 +1,35 @@
var events = require("events"),
util = require("../util").util,
hiredis = require("hiredis");
function HiredisReplyParser() {
this.reset();
events.EventEmitter.call(this);
}
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: true });
}
HiredisReplyParser.prototype.execute = function(data) {
var reply;
this.reader.feed(data);
try {
while ((reply = this.reader.get()) !== undefined) {
if (reply && reply.constructor == Error) {
this.emit("reply error", reply);
} else {
this.emit("reply", reply);
}
}
} catch(err) {
this.emit("error", err);
}
}