Authored by xiaofeng.yao@yoho.cn

Merge branch 'develop' into test

... ... @@ -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
... ...
... ... @@ -15,7 +15,6 @@ return [
'class' => 'common\components\caching\RedisCache',
'hostname' => '10.66.1.200',
'port' => 6379,
'database' => 5,
'connectionTimeout' => 0.5,
'dataTimeout' => 0.8,
],
... ... @@ -23,7 +22,6 @@ return [
'class' => 'common\components\caching\RedisCache',
'hostname' => '10.66.1.200',
'port' => 6379,
'database' => 0,
],
'db' => [
'class' => 'yii\db\Connection',
... ...
... ... @@ -67,7 +67,7 @@ class Connection extends Component
/**
* @var integer the redis database to use. This is an integer value starting from 0. Defaults to 0.
*/
public $database = 0;
public $database;
/**
* @var float timeout to use for connection to redis. If not set the timeout set in php.ini will be used: ini_get("default_socket_timeout")
*/
... ... @@ -238,7 +238,7 @@ class Connection extends Component
/**
* @var resource redis socket connection
*/
protected $_socket = false;
private $_socket = false;
/**
... ... @@ -286,7 +286,9 @@ class Connection extends Component
if ($this->password !== null) {
$this->executeCommand('AUTH', [$this->password]);
}
//$this->executeCommand('SELECT', [$this->database]);
if ($this->database !== null) {
$this->executeCommand('SELECT', [$this->database]);
}
$this->initConnection();
} else {
\Yii::error("Failed to open redis DB connection ($connection): $errorNumber - $errorDescription", __CLASS__);
... ... @@ -304,7 +306,7 @@ class Connection extends Component
if ($this->_socket !== false) {
$connection = ($this->unixSocket ?: $this->hostname . ':' . $this->port) . ', database=' . $this->database;
\Yii::trace('Closing DB connection: ' . $connection, __METHOD__);
//$this->executeCommand('QUIT');
$this->executeCommand('QUIT');
stream_socket_shutdown($this->_socket, STREAM_SHUT_RDWR);
$this->_socket = null;
}
... ...