You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Remove event emitters from the parser as they are overhead that is not needed
This commit is contained in:
14
index.js
14
index.js
@@ -302,18 +302,8 @@ RedisClient.prototype.init_parser = function () {
|
|||||||
this.reply_parser = new this.parser_module.Parser({
|
this.reply_parser = new this.parser_module.Parser({
|
||||||
return_buffers: self.options.return_buffers || self.options.detect_buffers || false
|
return_buffers: self.options.return_buffers || self.options.detect_buffers || false
|
||||||
});
|
});
|
||||||
|
this.reply_parser.send_error = this.return_error.bind(self);
|
||||||
// "reply error" is an error sent back by Redis
|
this.reply_parser.send_reply = this.return_reply.bind(self);
|
||||||
this.reply_parser.on("reply error", function (reply) {
|
|
||||||
self.return_error(reply);
|
|
||||||
});
|
|
||||||
this.reply_parser.on("reply", function (reply) {
|
|
||||||
self.return_reply(reply);
|
|
||||||
});
|
|
||||||
// "error" is bad. Somehow the parser got confused. It'll try to reset and continue.
|
|
||||||
this.reply_parser.on("error", function (err) {
|
|
||||||
self.emit("error", new Error("Redis reply parser error: " + err.stack));
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
RedisClient.prototype.on_ready = function () {
|
RedisClient.prototype.on_ready = function () {
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var events = require("events"),
|
var hiredis = require("hiredis");
|
||||||
util = require("util"),
|
|
||||||
hiredis = require("hiredis");
|
|
||||||
|
|
||||||
exports.name = "hiredis";
|
exports.name = "hiredis";
|
||||||
|
|
||||||
@@ -10,11 +8,8 @@ function HiredisReplyParser(options) {
|
|||||||
this.name = exports.name;
|
this.name = exports.name;
|
||||||
this.options = options || {};
|
this.options = options || {};
|
||||||
this.reset();
|
this.reset();
|
||||||
events.EventEmitter.call(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
util.inherits(HiredisReplyParser, events.EventEmitter);
|
|
||||||
|
|
||||||
exports.Parser = HiredisReplyParser;
|
exports.Parser = HiredisReplyParser;
|
||||||
|
|
||||||
HiredisReplyParser.prototype.reset = function () {
|
HiredisReplyParser.prototype.reset = function () {
|
||||||
@@ -27,21 +22,16 @@ HiredisReplyParser.prototype.execute = function (data) {
|
|||||||
var reply;
|
var reply;
|
||||||
this.reader.feed(data);
|
this.reader.feed(data);
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
reply = this.reader.get();
|
||||||
reply = this.reader.get();
|
|
||||||
} catch (err) {
|
|
||||||
this.emit("error", err);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reply === undefined) {
|
if (reply === undefined) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reply && reply.constructor === Error) {
|
if (reply && reply.constructor === Error) {
|
||||||
this.emit("reply error", reply);
|
this.send_error(reply);
|
||||||
} else {
|
} else {
|
||||||
this.emit("reply", reply);
|
this.send_reply(reply);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var events = require("events"),
|
var util = require("util");
|
||||||
util = require("util");
|
|
||||||
|
|
||||||
function Packet(type, size) {
|
function Packet(type, size) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@@ -20,8 +19,6 @@ function ReplyParser(options) {
|
|||||||
this._reply_type = null;
|
this._reply_type = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
util.inherits(ReplyParser, events.EventEmitter);
|
|
||||||
|
|
||||||
exports.Parser = ReplyParser;
|
exports.Parser = ReplyParser;
|
||||||
|
|
||||||
function IncompleteReadBuffer(message) {
|
function IncompleteReadBuffer(message) {
|
||||||
@@ -286,11 +283,3 @@ ReplyParser.prototype._packetEndOffset = function () {
|
|||||||
ReplyParser.prototype._bytesRemaining = function () {
|
ReplyParser.prototype._bytesRemaining = function () {
|
||||||
return (this._buffer.length - this._offset) < 0 ? 0 : (this._buffer.length - this._offset);
|
return (this._buffer.length - this._offset) < 0 ? 0 : (this._buffer.length - this._offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
ReplyParser.prototype.send_error = function (reply) {
|
|
||||||
this.emit("reply error", reply);
|
|
||||||
};
|
|
||||||
|
|
||||||
ReplyParser.prototype.send_reply = function (reply) {
|
|
||||||
this.emit("reply", reply);
|
|
||||||
};
|
|
||||||
|
@@ -11,7 +11,7 @@ describe('javascript parser', function () {
|
|||||||
assert.deepEqual(reply, [['a']], "Expecting multi-bulk reply of [['a']]");
|
assert.deepEqual(reply, [['a']], "Expecting multi-bulk reply of [['a']]");
|
||||||
reply_count++;
|
reply_count++;
|
||||||
}
|
}
|
||||||
parser.on("reply", check_reply);
|
parser.send_reply = check_reply;
|
||||||
|
|
||||||
parser.execute(new Buffer('*1\r\n*1\r\n$1\r\na\r\n'));
|
parser.execute(new Buffer('*1\r\n*1\r\n$1\r\na\r\n'));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user