Skip to content

Commit b63e980

Browse files
committed
Merge pull request #825 from fintura/emitter
Remove event emitters from the parsers
2 parents 62f9a0c + 0170145 commit b63e980

File tree

4 files changed

+7
-33
lines changed

4 files changed

+7
-33
lines changed

index.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -301,18 +301,8 @@ RedisClient.prototype.init_parser = function () {
301301
this.reply_parser = new this.parser_module.Parser({
302302
return_buffers: self.options.return_buffers || self.options.detect_buffers || false
303303
});
304-
305-
// "reply error" is an error sent back by Redis
306-
this.reply_parser.on("reply error", function (reply) {
307-
self.return_error(reply);
308-
});
309-
this.reply_parser.on("reply", function (reply) {
310-
self.return_reply(reply);
311-
});
312-
// "error" is bad. Somehow the parser got confused. It'll try to reset and continue.
313-
this.reply_parser.on("error", function (err) {
314-
self.emit("error", new Error("Redis reply parser error: " + err.stack));
315-
});
304+
this.reply_parser.send_error = this.return_error.bind(self);
305+
this.reply_parser.send_reply = this.return_reply.bind(self);
316306
};
317307

318308
RedisClient.prototype.on_ready = function () {

lib/parser/hiredis.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
'use strict';
22

3-
var events = require("events"),
4-
util = require("util"),
5-
hiredis = require("hiredis");
3+
var hiredis = require("hiredis");
64

75
exports.name = "hiredis";
86

97
function HiredisReplyParser(options) {
108
this.name = exports.name;
119
this.options = options;
1210
this.reset();
13-
events.EventEmitter.call(this);
1411
}
1512

16-
util.inherits(HiredisReplyParser, events.EventEmitter);
17-
1813
exports.Parser = HiredisReplyParser;
1914

2015
HiredisReplyParser.prototype.reset = function () {
@@ -34,9 +29,9 @@ HiredisReplyParser.prototype.execute = function (data) {
3429
}
3530

3631
if (reply && reply.constructor === Error) {
37-
this.emit("reply error", reply);
32+
this.send_error(reply);
3833
} else {
39-
this.emit("reply", reply);
34+
this.send_reply(reply);
4035
}
4136
}
4237
};

lib/parser/javascript.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

3-
var events = require("events"),
4-
util = require("util");
3+
var util = require("util");
54

65
function Packet(type, size) {
76
this.type = type;
@@ -20,8 +19,6 @@ function ReplyParser(options) {
2019
this._reply_type = null;
2120
}
2221

23-
util.inherits(ReplyParser, events.EventEmitter);
24-
2522
exports.Parser = ReplyParser;
2623

2724
function IncompleteReadBuffer(message) {
@@ -286,11 +283,3 @@ ReplyParser.prototype._packetEndOffset = function () {
286283
ReplyParser.prototype._bytesRemaining = function () {
287284
return (this._buffer.length - this._offset) < 0 ? 0 : (this._buffer.length - this._offset);
288285
};
289-
290-
ReplyParser.prototype.send_error = function (reply) {
291-
this.emit("reply error", reply);
292-
};
293-
294-
ReplyParser.prototype.send_reply = function (reply) {
295-
this.emit("reply", reply);
296-
};

test/parser/javascript.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('javascript parser', function () {
1111
assert.deepEqual(reply, [['a']], "Expecting multi-bulk reply of [['a']]");
1212
reply_count++;
1313
}
14-
parser.on("reply", check_reply);
14+
parser.send_reply = check_reply;
1515

1616
parser.execute(new Buffer('*1\r\n*1\r\n$1\r\na\r\n'));
1717

0 commit comments

Comments
 (0)