@@ -180,7 +180,12 @@ 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
+ // Backward compatibility support for auth with password only
185
+ if ( user instanceof Function ) {
186
+ callback = user ;
187
+ user = null ;
188
+ }
184
189
return function ( err , res ) {
185
190
if ( err ) {
186
191
if ( no_password_is_set . test ( err . message ) ) {
@@ -191,7 +196,7 @@ function auth_callback (self, pass, callback) {
191
196
// If redis is still loading the db, it will not authenticate and everything else will fail
192
197
debug ( 'Redis still loading, trying to authenticate later' ) ;
193
198
setTimeout ( function ( ) {
194
- self . auth ( pass , callback ) ;
199
+ self . auth ( pass , user , callback ) ;
195
200
} , 100 ) ;
196
201
return ;
197
202
}
@@ -200,25 +205,46 @@ function auth_callback (self, pass, callback) {
200
205
} ;
201
206
}
202
207
203
- RedisClient . prototype . auth = RedisClient . prototype . AUTH = function auth ( pass , callback ) {
208
+ RedisClient . prototype . auth = RedisClient . prototype . AUTH = function auth ( pass , user , callback ) {
204
209
debug ( 'Sending auth to ' + this . address + ' id ' + this . connection_id ) ;
205
210
211
+ // Backward compatibility support for auth with password only
212
+ if ( user instanceof Function ) {
213
+ callback = user ;
214
+ user = null ;
215
+ }
206
216
// Stash auth for connect and reconnect.
207
217
this . auth_pass = pass ;
218
+ this . auth_user = user ;
208
219
var ready = this . ready ;
209
220
this . ready = ready || this . offline_queue . length === 0 ;
210
- var tmp = this . internal_send_command ( new Command ( 'auth' , [ pass ] , auth_callback ( this , pass , callback ) ) ) ;
221
+ var tmp ;
222
+ if ( user ) {
223
+ tmp = this . internal_send_command ( new Command ( 'auth' , [ pass , user ] , auth_callback ( this , pass , user , callback ) ) ) ;
224
+ } else {
225
+ tmp = this . internal_send_command ( new Command ( 'auth' , [ pass ] , auth_callback ( this , pass , callback ) ) ) ;
226
+ }
211
227
this . ready = ready ;
212
228
return tmp ;
213
229
} ;
214
230
215
231
// Only works with batch, not in a transaction
216
- Multi . prototype . auth = Multi . prototype . AUTH = function auth ( pass , callback ) {
232
+ Multi . prototype . auth = Multi . prototype . AUTH = function auth ( pass , user , callback ) {
217
233
debug ( 'Sending auth to ' + this . address + ' id ' + this . connection_id ) ;
218
234
235
+ // Backward compatibility support for auth with password only
236
+ if ( user instanceof Function ) {
237
+ callback = user ;
238
+ user = null ;
239
+ }
219
240
// Stash auth for connect and reconnect.
220
241
this . auth_pass = pass ;
221
- this . queue . push ( new Command ( 'auth' , [ pass ] , auth_callback ( this . _client , callback ) ) ) ;
242
+ this . auth_user = user ;
243
+ if ( user ) {
244
+ this . queue . push ( new Command ( 'auth' , [ pass , user ] , auth_callback ( this . _client , callback ) ) ) ;
245
+ } else {
246
+ this . queue . push ( new Command ( 'auth' , [ pass ] , auth_callback ( this . _client , callback ) ) ) ;
247
+ }
222
248
return this ;
223
249
} ;
224
250
0 commit comments