@@ -180,7 +180,7 @@ Multi.prototype.info = Multi.prototype.INFO = function info (section, callback)
180
180
return this ;
181
181
} ;
182
182
183
- function auth_callback ( self , pass , callback ) {
183
+ function auth_callback ( self , pass , user , callback ) {
184
184
return function ( err , res ) {
185
185
if ( err ) {
186
186
if ( no_password_is_set . test ( err . message ) ) {
@@ -191,7 +191,7 @@ function auth_callback (self, pass, callback) {
191
191
// If redis is still loading the db, it will not authenticate and everything else will fail
192
192
debug ( 'Redis still loading, trying to authenticate later' ) ;
193
193
setTimeout ( function ( ) {
194
- self . auth ( pass , callback ) ;
194
+ self . auth ( user , pass , callback ) ;
195
195
} , 100 ) ;
196
196
return ;
197
197
}
@@ -200,25 +200,37 @@ function auth_callback (self, pass, callback) {
200
200
} ;
201
201
}
202
202
203
- RedisClient . prototype . auth = RedisClient . prototype . AUTH = function auth ( pass , callback ) {
203
+ RedisClient . prototype . auth = RedisClient . prototype . AUTH = function auth ( pass , user , callback ) {
204
204
debug ( 'Sending auth to ' + this . address + ' id ' + this . connection_id ) ;
205
205
206
+ // Backward compatibility support for auth with password only
207
+ if ( user instanceof Function ) {
208
+ callback = user ;
209
+ user = null ;
210
+ }
206
211
// Stash auth for connect and reconnect.
207
212
this . auth_pass = pass ;
213
+ this . auth_user = user ;
208
214
var ready = this . ready ;
209
215
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 ) ) ) ;
211
217
this . ready = ready ;
212
218
return tmp ;
213
219
} ;
214
220
215
221
// 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 ) {
217
223
debug ( 'Sending auth to ' + this . address + ' id ' + this . connection_id ) ;
218
224
225
+ // Backward compatibility support for auth with password only
226
+ if ( user instanceof Function ) {
227
+ callback = user ;
228
+ user = null ;
229
+ }
219
230
// Stash auth for connect and reconnect.
220
231
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 ) ) ) ;
222
234
return this ;
223
235
} ;
224
236
0 commit comments