PHP & Redis (Predis)

If redis doesn’t have a password, don’t include password parameter in connection URL.

Connection example

private function init()
{
    $host = $this->_ci->config->item('redis_host');
    $password = $this->_ci->config->item('redis_password');
    $port = $this->_ci->config->item('redis_port');
    $db = $this->_ci->config->item('redis_db');

    $url = "tcp://{$host}:{$port}?database={$db}";
    if($password != false){
        $url .= "&password={$password}";
    }
    $this->_connection = new Client($url);
}

Standard

$redis = new Client([
    'scheme' => 'tcp', 
    'host' => $host, 
    'port' => $port, 
    'password' => $password, 
    'database' => $db
]);