class Redis::Client

def connect

def connect
  @pid = Process.pid
  # Don't try to reconnect when the connection is fresh
  with_reconnect(false) do
    establish_connection
    if password
      if username
        begin
          call [:auth, username, password]
        rescue CommandError => err # Likely on Redis < 6
          case err.message
          when /ERR wrong number of arguments for 'auth' command/
            call [:auth, password]
          when /WRONGPASS invalid username-password pair/
            begin
              call [:auth, password]
            rescue CommandError
              raise err
            end
            ::Redis.deprecate!(
              "[redis-rb] The Redis connection was configured with username #{username.inspect}, but" \
              " the provided password was for the default user. This will start failing in redis-rb 5.0.0."
            )
          else
            raise
          end
        end
      else
        call [:auth, password]
      end
    end
    call [:readonly] if @options[:readonly]
    call [:select, db] if db != 0
    call [:client, :setname, @options[:id]] if @options[:id]
    @connector.check(self)
  end
  self
end