diff --git a/lib/extendedApi.js b/lib/extendedApi.js index bac36914139..27ed4215d6a 100644 --- a/lib/extendedApi.js +++ b/lib/extendedApi.js @@ -95,7 +95,7 @@ RedisClient.prototype.duplicate = function (options, callback) { existing_options[elem] = options[elem]; } var client = new RedisClient(existing_options); - client.selected_db = this.selected_db; + client.selected_db = options.db || this.selected_db; if (typeof callback === 'function') { var ready_listener = function () { callback(null, client); diff --git a/test/node_redis.spec.js b/test/node_redis.spec.js index 1557730312c..3375b759d91 100644 --- a/test/node_redis.spec.js +++ b/test/node_redis.spec.js @@ -120,11 +120,14 @@ describe('The node_redis client', function () { }); it('check if all new options replaced the old ones', function (done) { + client.selected_db = 1; var client2 = client.duplicate({ + db: 2, no_ready_check: true }); assert(client.connected); assert(!client2.connected); + assert.notEqual(client.selected_db, client2.selected_db); assert.strictEqual(client.options.no_ready_check, undefined); assert.strictEqual(client2.options.no_ready_check, true); assert.notDeepEqual(client.options, client2.options);