commit
ffd5769416
|
@ -16,6 +16,13 @@ class Redis {
|
||||||
*/
|
*/
|
||||||
protected $port;
|
protected $port;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The database password, if present.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $password;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The database number the connection selects on load.
|
* The database number the connection selects on load.
|
||||||
*
|
*
|
||||||
|
@ -45,10 +52,11 @@ class Redis {
|
||||||
* @param int $database
|
* @param int $database
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($host, $port, $database = 0)
|
public function __construct($host, $port, $password = null, $database = 0)
|
||||||
{
|
{
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
$this->port = $port;
|
$this->port = $port;
|
||||||
|
$this->password = $password;
|
||||||
$this->database = $database;
|
$this->database = $database;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +87,12 @@ public static function db($name = 'default')
|
||||||
|
|
||||||
extract($config);
|
extract($config);
|
||||||
|
|
||||||
static::$databases[$name] = new static($host, $port, $database);
|
if ( ! isset($password))
|
||||||
|
{
|
||||||
|
$password = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static::$databases[$name] = new static($host, $port, $password, $database);
|
||||||
}
|
}
|
||||||
|
|
||||||
return static::$databases[$name];
|
return static::$databases[$name];
|
||||||
|
@ -153,6 +166,11 @@ protected function connect()
|
||||||
throw new \Exception("Error making Redis connection: {$error} - {$message}");
|
throw new \Exception("Error making Redis connection: {$error} - {$message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( $this->password )
|
||||||
|
{
|
||||||
|
$this->auth($this->password);
|
||||||
|
}
|
||||||
|
|
||||||
$this->select($this->database);
|
$this->select($this->database);
|
||||||
|
|
||||||
return $this->connection;
|
return $this->connection;
|
||||||
|
|
Loading…
Reference in New Issue