Skip to content

Commit 634dcee

Browse files
author
Ruben Bridgewater
committed
Only initiate the parser once per instance and throw sync if the parser can't be found
1 parent d3352bf commit 634dcee

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ function RedisClient(options) {
9090
this.old_state = null;
9191
this.pipeline = 0;
9292
this.options = options;
93-
93+
// Init parser once per instance
94+
this.init_parser();
9495
self.stream = net.createConnection(cnx_options);
9596
self.install_stream_listeners();
9697
}
@@ -256,8 +257,6 @@ RedisClient.prototype.on_connect = function () {
256257
this.stream.setKeepAlive(this.options.socket_keepalive);
257258
this.stream.setTimeout(0);
258259

259-
this.init_parser();
260-
261260
if (typeof this.auth_pass === 'string') {
262261
this.do_auth();
263262
} else {

test/node_redis.spec.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@ describe("The node_redis client", function () {
1010

1111
describe("testing parser existence", function () {
1212
it('throws on non-existence', function (done) {
13-
var mochaListener = helper.removeMochaListener();
14-
15-
process.once('uncaughtException', function (err) {
16-
process.on('uncaughtException', mochaListener);
13+
try {
14+
redis.createClient({
15+
parser: 'nonExistingParser'
16+
});
17+
done(new Error('test failed'));
18+
} catch (err) {
1719
assert.equal(err.message, 'Couldn\'t find named parser nonExistingParser on this system');
18-
return done();
19-
});
20-
21-
redis.createClient({
22-
parser: 'nonExistingParser'
23-
});
20+
done();
21+
}
2422
});
2523
});
2624

0 commit comments

Comments
 (0)