Skip to content

Commit

Permalink
Update individualCommands.js
Browse files Browse the repository at this point in the history
Clean code
  • Loading branch information
leibale committed Mar 8, 2021
1 parent 11c1503 commit 8c898fb
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions lib/individualCommands.js
Expand Up @@ -180,12 +180,7 @@ Multi.prototype.info = Multi.prototype.INFO = function info (section, callback)
return this;
};

function auth_callback (self, user, pass, callback) {
// Backward compatibility support for auth with password only
if (user instanceof Function) {
callback = user;
user = null;
}
function auth_callback (self, pass, user, callback) {
return function (err, res) {
if (err) {
if (no_password_is_set.test(err.message)) {
Expand All @@ -205,7 +200,7 @@ function auth_callback (self, user, pass, callback) {
};
}

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

// Backward compatibility support for auth with password only
Expand All @@ -220,16 +215,16 @@ RedisClient.prototype.auth = RedisClient.prototype.AUTH = function auth (user, p
this.ready = ready || this.offline_queue.length === 0;
var tmp;
if (user) {
tmp = this.internal_send_command(new Command('auth', [user, pass], auth_callback(this, user, pass, callback)));
tmp = this.internal_send_command(new Command('auth', [user, pass], auth_callback(this, pass, user, callback)));
} else {
tmp = this.internal_send_command(new Command('auth', [pass], auth_callback(this, pass, callback)));
tmp = this.internal_send_command(new Command('auth', [pass], auth_callback(this, pass, user, callback)));
}
this.ready = ready;
return tmp;
};

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

// Backward compatibility support for auth with password only
Expand All @@ -240,11 +235,7 @@ Multi.prototype.auth = Multi.prototype.AUTH = function auth (user, pass, callbac
// Stash auth for connect and reconnect.
this.auth_pass = pass;
this.auth_user = user;
if (user) {
this.queue.push(new Command('auth', [user, pass], auth_callback(this._client, callback)));
} else {
this.queue.push(new Command('auth', [pass], auth_callback(this._client, callback)));
}
this.queue.push(new Command('auth', user ? [user, pass] : [pass], auth_callback(this._client, pass, user, callback)));
return this;
};

Expand Down

0 comments on commit 8c898fb

Please sign in to comment.