...
|
...
|
@@ -38,54 +38,4 @@ class RedisCache extends \yii\redis\Connection |
|
|
return parent::__call($name, $params);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Establishes a DB connection.
|
|
|
* It does nothing if a DB connection has already been established.
|
|
|
* @throws Exception if connection fails
|
|
|
*/
|
|
|
public function open()
|
|
|
{
|
|
|
if ($this->_socket !== false) {
|
|
|
return;
|
|
|
}
|
|
|
$connection = ($this->unixSocket ?: $this->hostname . ':' . $this->port) . ', database=' . $this->database;
|
|
|
\Yii::trace('Opening redis DB connection: ' . $connection, __METHOD__);
|
|
|
$this->_socket = @stream_socket_client(
|
|
|
$this->unixSocket ? 'unix://' . $this->unixSocket : 'tcp://' . $this->hostname . ':' . $this->port,
|
|
|
$errorNumber,
|
|
|
$errorDescription,
|
|
|
$this->connectionTimeout ? $this->connectionTimeout : ini_get("default_socket_timeout"),
|
|
|
$this->socketClientFlags
|
|
|
);
|
|
|
if ($this->_socket) {
|
|
|
if ($this->dataTimeout !== null) {
|
|
|
stream_set_timeout($this->_socket, $timeout = (int) $this->dataTimeout, (int) (($this->dataTimeout - $timeout) * 1000000));
|
|
|
}
|
|
|
if ($this->password !== null) {
|
|
|
$this->executeCommand('AUTH', [$this->password]);
|
|
|
}
|
|
|
//$this->executeCommand('SELECT', [$this->database]);
|
|
|
$this->initConnection();
|
|
|
} else {
|
|
|
\Yii::error("Failed to open redis DB connection ($connection): $errorNumber - $errorDescription", __CLASS__);
|
|
|
$message = YII_DEBUG ? "Failed to open redis DB connection ($connection): $errorNumber - $errorDescription" : 'Failed to open DB connection.';
|
|
|
throw new Exception($message, $errorDescription, (int) $errorNumber);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Closes the currently active DB connection.
|
|
|
* It does nothing if the connection is already closed.
|
|
|
*/
|
|
|
public function close()
|
|
|
{
|
|
|
if ($this->_socket !== false) {
|
|
|
$connection = ($this->unixSocket ?: $this->hostname . ':' . $this->port) . ', database=' . $this->database;
|
|
|
\Yii::trace('Closing DB connection: ' . $connection, __METHOD__);
|
|
|
//$this->executeCommand('QUIT');
|
|
|
stream_socket_shutdown($this->_socket, STREAM_SHUT_RDWR);
|
|
|
$this->_socket = null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|