@@ -180,7 +180,7 @@ Multi.prototype.info = Multi.prototype.INFO = function info (section, callback)
180180 return this ;
181181} ;
182182
183- function auth_callback ( self , pass , callback ) {
183+ function auth_callback ( self , pass , user , callback ) {
184184 return function ( err , res ) {
185185 if ( err ) {
186186 if ( no_password_is_set . test ( err . message ) ) {
@@ -191,7 +191,7 @@ function auth_callback (self, pass, callback) {
191191 // If redis is still loading the db, it will not authenticate and everything else will fail
192192 debug ( 'Redis still loading, trying to authenticate later' ) ;
193193 setTimeout ( function ( ) {
194- self . auth ( pass , callback ) ;
194+ self . auth ( user , pass , callback ) ;
195195 } , 100 ) ;
196196 return ;
197197 }
@@ -200,25 +200,37 @@ function auth_callback (self, pass, callback) {
200200 } ;
201201}
202202
203- RedisClient . prototype . auth = RedisClient . prototype . AUTH = function auth ( pass , callback ) {
203+ RedisClient . prototype . auth = RedisClient . prototype . AUTH = function auth ( pass , user , callback ) {
204204 debug ( 'Sending auth to ' + this . address + ' id ' + this . connection_id ) ;
205205
206+ // Backward compatibility support for auth with password only
207+ if ( user instanceof Function ) {
208+ callback = user ;
209+ user = null ;
210+ }
206211 // Stash auth for connect and reconnect.
207212 this . auth_pass = pass ;
213+ this . auth_user = user ;
208214 var ready = this . ready ;
209215 this . ready = ready || this . offline_queue . length === 0 ;
210- var tmp = this . internal_send_command ( new Command ( 'auth' , [ pass ] , auth_callback ( this , pass , callback ) ) ) ;
216+ var tmp = this . internal_send_command ( new Command ( 'auth' , user ? [ user , pass ] : [ pass ] , auth_callback ( this , pass , user , callback ) ) ) ;
211217 this . ready = ready ;
212218 return tmp ;
213219} ;
214220
215221// Only works with batch, not in a transaction
216- Multi . prototype . auth = Multi . prototype . AUTH = function auth ( pass , callback ) {
222+ Multi . prototype . auth = Multi . prototype . AUTH = function auth ( pass , user , callback ) {
217223 debug ( 'Sending auth to ' + this . address + ' id ' + this . connection_id ) ;
218224
225+ // Backward compatibility support for auth with password only
226+ if ( user instanceof Function ) {
227+ callback = user ;
228+ user = null ;
229+ }
219230 // Stash auth for connect and reconnect.
220231 this . auth_pass = pass ;
221- this . queue . push ( new Command ( 'auth' , [ pass ] , auth_callback ( this . _client , callback ) ) ) ;
232+ this . auth_user = user ;
233+ this . queue . push ( new Command ( 'auth' , user ? [ user , pass ] : [ pass ] , auth_callback ( this . _client , pass , user , callback ) ) ) ;
222234 return this ;
223235} ;
224236
0 commit comments