diff --git a/index.js b/index.js index c41f0c82a2..b3c5669b46 100644 --- a/index.js +++ b/index.js @@ -141,7 +141,9 @@ RedisClient.prototype.duplicate = function (options) { for (var elem in options) { // jshint ignore: line existing_options[elem] = options[elem]; } - return new RedisClient(existing_options); + var client = new RedisClient(existing_options); + client.selected_db = this.selected_db; + return client; }; RedisClient.prototype.initialize_retry_vars = function () { diff --git a/test/node_redis.spec.js b/test/node_redis.spec.js index 39cabc8118..547dbc6251 100644 --- a/test/node_redis.spec.js +++ b/test/node_redis.spec.js @@ -44,7 +44,9 @@ describe("The node_redis client", function () { describe('duplicate', function () { it('check if all options got copied properly', function(done) { + client.selected_db = 2; var client2 = client.duplicate(); + assert.strictEqual(client2.selected_db, 2); assert(client.connected); assert(!client2.connected); for (var elem in client.options) {