@@ -4,6 +4,7 @@ var utils = require('./utils');
4
4
var debug = require ( './debug' ) ;
5
5
var Multi = require ( './multi' ) ;
6
6
var no_password_is_set = / n o p a s s w o r d i s s e t / ;
7
+ var loading = / L O A D I N G / ;
7
8
var RedisClient = require ( '../' ) . RedisClient ;
8
9
9
10
/********************************
@@ -91,12 +92,20 @@ RedisClient.prototype.auth = RedisClient.prototype.AUTH = function auth (pass, c
91
92
this . auth_pass = pass ;
92
93
this . ready = this . offline_queue . length === 0 ; // keep the execution order intakt
93
94
var tmp = this . send_command ( 'auth' , [ pass ] , function ( err , res ) {
94
- if ( err && no_password_is_set . test ( err . message ) ) {
95
- self . warn ( 'Warning: Redis server does not require a password, but a password was supplied.' ) ;
96
- err = null ;
97
- res = 'OK' ;
95
+ if ( err ) {
96
+ if ( no_password_is_set . test ( err . message ) ) {
97
+ self . warn ( 'Warning: Redis server does not require a password, but a password was supplied.' ) ;
98
+ err = null ;
99
+ res = 'OK' ;
100
+ } else if ( loading . test ( err . message ) ) {
101
+ // If redis is still loading the db, it will not authenticate and everything else will fail
102
+ debug ( 'Redis still loading, trying to authenticate later' ) ;
103
+ setTimeout ( function ( ) {
104
+ self . auth ( pass , callback ) ;
105
+ } , 200 ) ;
106
+ return ;
107
+ }
98
108
}
99
-
100
109
utils . callback_or_emit ( self , callback , err , res ) ;
101
110
} ) ;
102
111
this . ready = ready ;
0 commit comments