Skip to content

Commit bc85c4a

Browse files
author
Ruben Bridgewater
committed
Minor hiredis handling improvement
1 parent 634dcee commit bc85c4a

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ RedisClient.prototype.init_parser = function () {
293293

294294
// return_buffers sends back Buffers from parser to callback. detect_buffers sends back Buffers from parser, but
295295
// converts to Strings if the input arguments are not Buffers.
296-
this.reply_parser = new this.parser_module.Parser(self.options.return_buffers || self.options.detect_buffers || false);
296+
this.reply_parser = new this.parser_module.Parser(self.options.return_buffers || self.options.detect_buffers);
297297
// Important: Only send results / errors async.
298298
// That way the result / error won't stay in a try catch block and catch user things
299299
this.reply_parser.send_error = function (data) {

lib/parsers/hiredis.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,32 @@ var hiredis = require('hiredis');
44

55
function HiredisReplyParser(return_buffers) {
66
this.name = exports.name;
7-
this.return_buffers = return_buffers;
8-
this.reset();
9-
}
10-
11-
HiredisReplyParser.prototype.reset = function () {
127
this.reader = new hiredis.Reader({
13-
return_buffers: this.return_buffers || false
8+
return_buffers: return_buffers
149
});
10+
}
11+
12+
HiredisReplyParser.prototype.return_data = function () {
13+
try {
14+
return this.reader.get();
15+
} catch (err) {
16+
// Protocol errors land here
17+
this.send_error(err);
18+
return void 0;
19+
}
1520
};
1621

1722
HiredisReplyParser.prototype.execute = function (data) {
18-
var reply;
1923
this.reader.feed(data);
20-
while (true) {
21-
try {
22-
reply = this.reader.get();
23-
} catch (err) {
24-
// Protocol errors land here
25-
this.send_error(err);
26-
break;
27-
}
28-
29-
if (reply === undefined) {
30-
break;
31-
}
24+
var reply = this.return_data();
3225

33-
if (reply && reply.constructor === Error) {
26+
while (reply !== undefined) {
27+
if (reply && reply.name === 'Error') {
3428
this.send_error(reply);
3529
} else {
3630
this.send_reply(reply);
3731
}
32+
reply = this.return_data();
3833
}
3934
};
4035

0 commit comments

Comments
 (0)