Skip to content

Commit 8c898fb

Browse files
authored
Update individualCommands.js
Clean code
1 parent 11c1503 commit 8c898fb

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

lib/individualCommands.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,7 @@ Multi.prototype.info = Multi.prototype.INFO = function info (section, callback)
180180
return this;
181181
};
182182

183-
function auth_callback (self, user, pass, callback) {
184-
// Backward compatibility support for auth with password only
185-
if (user instanceof Function) {
186-
callback = user;
187-
user = null;
188-
}
183+
function auth_callback (self, pass, user, callback) {
189184
return function (err, res) {
190185
if (err) {
191186
if (no_password_is_set.test(err.message)) {
@@ -205,7 +200,7 @@ function auth_callback (self, user, pass, callback) {
205200
};
206201
}
207202

208-
RedisClient.prototype.auth = RedisClient.prototype.AUTH = function auth (user, pass, callback) {
203+
RedisClient.prototype.auth = RedisClient.prototype.AUTH = function auth (pass, user, callback) {
209204
debug('Sending auth to ' + this.address + ' id ' + this.connection_id);
210205

211206
// Backward compatibility support for auth with password only
@@ -220,16 +215,16 @@ RedisClient.prototype.auth = RedisClient.prototype.AUTH = function auth (user, p
220215
this.ready = ready || this.offline_queue.length === 0;
221216
var tmp;
222217
if (user) {
223-
tmp = this.internal_send_command(new Command('auth', [user, pass], auth_callback(this, user, pass, callback)));
218+
tmp = this.internal_send_command(new Command('auth', [user, pass], auth_callback(this, pass, user, callback)));
224219
} else {
225-
tmp = this.internal_send_command(new Command('auth', [pass], auth_callback(this, pass, callback)));
220+
tmp = this.internal_send_command(new Command('auth', [pass], auth_callback(this, pass, user, callback)));
226221
}
227222
this.ready = ready;
228223
return tmp;
229224
};
230225

231226
// Only works with batch, not in a transaction
232-
Multi.prototype.auth = Multi.prototype.AUTH = function auth (user, pass, callback) {
227+
Multi.prototype.auth = Multi.prototype.AUTH = function auth (pass, user, callback) {
233228
debug('Sending auth to ' + this.address + ' id ' + this.connection_id);
234229

235230
// Backward compatibility support for auth with password only
@@ -240,11 +235,7 @@ Multi.prototype.auth = Multi.prototype.AUTH = function auth (user, pass, callbac
240235
// Stash auth for connect and reconnect.
241236
this.auth_pass = pass;
242237
this.auth_user = user;
243-
if (user) {
244-
this.queue.push(new Command('auth', [user, pass], auth_callback(this._client, callback)));
245-
} else {
246-
this.queue.push(new Command('auth', [pass], auth_callback(this._client, callback)));
247-
}
238+
this.queue.push(new Command('auth', user ? [user, pass] : [pass], auth_callback(this._client, pass, user, callback)));
248239
return this;
249240
};
250241

0 commit comments

Comments
 (0)