From 8c898fbef1d6efa1e590ea13c0a62ecf337ea574 Mon Sep 17 00:00:00 2001 From: Leibale Eidelman Date: Mon, 8 Mar 2021 16:49:10 -0500 Subject: [PATCH] Update individualCommands.js Clean code --- lib/individualCommands.js | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/individualCommands.js b/lib/individualCommands.js index 47a5f991d4a..091f63131d8 100644 --- a/lib/individualCommands.js +++ b/lib/individualCommands.js @@ -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)) { @@ -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 @@ -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 @@ -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; };