diff --git a/index.js b/index.js index 78e07e6579..b5c62f3c65 100644 --- a/index.js +++ b/index.js @@ -269,7 +269,9 @@ RedisClient.prototype.create_stream = function () { // Fire the command before redis is connected to be sure it's the first fired command if (this.auth_pass !== undefined) { + this.ready = true; this.auth(this.auth_pass); + this.ready = false; } }; diff --git a/lib/individualCommands.js b/lib/individualCommands.js index 4f4c8ab7a5..953a9337f2 100644 --- a/lib/individualCommands.js +++ b/lib/individualCommands.js @@ -149,7 +149,7 @@ RedisClient.prototype.auth = RedisClient.prototype.AUTH = function auth (pass, c // Stash auth for connect and reconnect. this.auth_pass = pass; - this.ready = this.offline_queue.length === 0; // keep the execution order intakt + this.ready = ready || this.offline_queue.length === 0; // keep the execution order intakt var tmp = this.internal_send_command('auth', [pass], function (err, res) { if (err) { if (no_password_is_set.test(err.message)) { diff --git a/test/auth.spec.js b/test/auth.spec.js index b9bb3c033c..2e28f895df 100644 --- a/test/auth.spec.js +++ b/test/auth.spec.js @@ -160,7 +160,7 @@ describe('client authentication', function () { client.on('ready', done); }); - it('reconnects with appropriate authentication', function (done) { + it('reconnects with appropriate authentication while offline commands are present', function (done) { if (helper.redisProcess().spawnFailed()) this.skip(); client = redis.createClient.apply(null, args); @@ -187,7 +187,7 @@ describe('client authentication', function () { }); }); - it('should return an error if the password is not of type string and a callback has been provided', function (done) { + it('should return an error if the password is not correct and a callback has been provided', function (done) { if (helper.redisProcess().spawnFailed()) this.skip(); client = redis.createClient.apply(null, args); @@ -202,7 +202,7 @@ describe('client authentication', function () { assert(async); }); - it('should emit an error if the password is not of type string and no callback has been provided', function (done) { + it('should emit an error if the password is not correct and no callback has been provided', function (done) { if (helper.redisProcess().spawnFailed()) this.skip(); client = redis.createClient.apply(null, args);