Skip to content

Commit b5fe822

Browse files
author
Ruben Bridgewater
committed
Add selected_db to the new redis instance if using client.duplicate
1 parent 9ca2d1d commit b5fe822

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ RedisClient.prototype.duplicate = function (options) {
141141
for (var elem in options) { // jshint ignore: line
142142
existing_options[elem] = options[elem];
143143
}
144-
return new RedisClient(existing_options);
144+
var client = new RedisClient(existing_options);
145+
client.selected_db = this.selected_db;
146+
return client;
145147
};
146148

147149
RedisClient.prototype.initialize_retry_vars = function () {

test/node_redis.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ describe("The node_redis client", function () {
4444

4545
describe('duplicate', function () {
4646
it('check if all options got copied properly', function(done) {
47+
client.selected_db = 2;
4748
var client2 = client.duplicate();
49+
assert.strictEqual(client2.selected_db, 2);
4850
assert(client.connected);
4951
assert(!client2.connected);
5052
for (var elem in client.options) {

0 commit comments

Comments
 (0)