Merge branch 'develop' into test
Showing
3 changed files
with
6 additions
and
56 deletions
@@ -38,54 +38,4 @@ class RedisCache extends \yii\redis\Connection | @@ -38,54 +38,4 @@ class RedisCache extends \yii\redis\Connection | ||
38 | return parent::__call($name, $params); | 38 | return parent::__call($name, $params); |
39 | } | 39 | } |
40 | 40 | ||
41 | - /** | ||
42 | - * Establishes a DB connection. | ||
43 | - * It does nothing if a DB connection has already been established. | ||
44 | - * @throws Exception if connection fails | ||
45 | - */ | ||
46 | - public function open() | ||
47 | - { | ||
48 | - if ($this->_socket !== false) { | ||
49 | - return; | ||
50 | - } | ||
51 | - $connection = ($this->unixSocket ?: $this->hostname . ':' . $this->port) . ', database=' . $this->database; | ||
52 | - \Yii::trace('Opening redis DB connection: ' . $connection, __METHOD__); | ||
53 | - $this->_socket = @stream_socket_client( | ||
54 | - $this->unixSocket ? 'unix://' . $this->unixSocket : 'tcp://' . $this->hostname . ':' . $this->port, | ||
55 | - $errorNumber, | ||
56 | - $errorDescription, | ||
57 | - $this->connectionTimeout ? $this->connectionTimeout : ini_get("default_socket_timeout"), | ||
58 | - $this->socketClientFlags | ||
59 | - ); | ||
60 | - if ($this->_socket) { | ||
61 | - if ($this->dataTimeout !== null) { | ||
62 | - stream_set_timeout($this->_socket, $timeout = (int) $this->dataTimeout, (int) (($this->dataTimeout - $timeout) * 1000000)); | ||
63 | - } | ||
64 | - if ($this->password !== null) { | ||
65 | - $this->executeCommand('AUTH', [$this->password]); | ||
66 | - } | ||
67 | - //$this->executeCommand('SELECT', [$this->database]); | ||
68 | - $this->initConnection(); | ||
69 | - } else { | ||
70 | - \Yii::error("Failed to open redis DB connection ($connection): $errorNumber - $errorDescription", __CLASS__); | ||
71 | - $message = YII_DEBUG ? "Failed to open redis DB connection ($connection): $errorNumber - $errorDescription" : 'Failed to open DB connection.'; | ||
72 | - throw new Exception($message, $errorDescription, (int) $errorNumber); | ||
73 | - } | ||
74 | - } | ||
75 | - | ||
76 | - /** | ||
77 | - * Closes the currently active DB connection. | ||
78 | - * It does nothing if the connection is already closed. | ||
79 | - */ | ||
80 | - public function close() | ||
81 | - { | ||
82 | - if ($this->_socket !== false) { | ||
83 | - $connection = ($this->unixSocket ?: $this->hostname . ':' . $this->port) . ', database=' . $this->database; | ||
84 | - \Yii::trace('Closing DB connection: ' . $connection, __METHOD__); | ||
85 | - //$this->executeCommand('QUIT'); | ||
86 | - stream_socket_shutdown($this->_socket, STREAM_SHUT_RDWR); | ||
87 | - $this->_socket = null; | ||
88 | - } | ||
89 | - } | ||
90 | - | ||
91 | } | 41 | } |
@@ -15,7 +15,6 @@ return [ | @@ -15,7 +15,6 @@ return [ | ||
15 | 'class' => 'common\components\caching\RedisCache', | 15 | 'class' => 'common\components\caching\RedisCache', |
16 | 'hostname' => '10.66.1.200', | 16 | 'hostname' => '10.66.1.200', |
17 | 'port' => 6379, | 17 | 'port' => 6379, |
18 | - 'database' => 5, | ||
19 | 'connectionTimeout' => 0.5, | 18 | 'connectionTimeout' => 0.5, |
20 | 'dataTimeout' => 0.8, | 19 | 'dataTimeout' => 0.8, |
21 | ], | 20 | ], |
@@ -23,7 +22,6 @@ return [ | @@ -23,7 +22,6 @@ return [ | ||
23 | 'class' => 'common\components\caching\RedisCache', | 22 | 'class' => 'common\components\caching\RedisCache', |
24 | 'hostname' => '10.66.1.200', | 23 | 'hostname' => '10.66.1.200', |
25 | 'port' => 6379, | 24 | 'port' => 6379, |
26 | - 'database' => 0, | ||
27 | ], | 25 | ], |
28 | 'db' => [ | 26 | 'db' => [ |
29 | 'class' => 'yii\db\Connection', | 27 | 'class' => 'yii\db\Connection', |
@@ -67,7 +67,7 @@ class Connection extends Component | @@ -67,7 +67,7 @@ class Connection extends Component | ||
67 | /** | 67 | /** |
68 | * @var integer the redis database to use. This is an integer value starting from 0. Defaults to 0. | 68 | * @var integer the redis database to use. This is an integer value starting from 0. Defaults to 0. |
69 | */ | 69 | */ |
70 | - public $database = 0; | 70 | + public $database; |
71 | /** | 71 | /** |
72 | * @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") | 72 | * @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") |
73 | */ | 73 | */ |
@@ -238,7 +238,7 @@ class Connection extends Component | @@ -238,7 +238,7 @@ class Connection extends Component | ||
238 | /** | 238 | /** |
239 | * @var resource redis socket connection | 239 | * @var resource redis socket connection |
240 | */ | 240 | */ |
241 | - protected $_socket = false; | 241 | + private $_socket = false; |
242 | 242 | ||
243 | 243 | ||
244 | /** | 244 | /** |
@@ -286,7 +286,9 @@ class Connection extends Component | @@ -286,7 +286,9 @@ class Connection extends Component | ||
286 | if ($this->password !== null) { | 286 | if ($this->password !== null) { |
287 | $this->executeCommand('AUTH', [$this->password]); | 287 | $this->executeCommand('AUTH', [$this->password]); |
288 | } | 288 | } |
289 | - //$this->executeCommand('SELECT', [$this->database]); | 289 | + if ($this->database !== null) { |
290 | + $this->executeCommand('SELECT', [$this->database]); | ||
291 | + } | ||
290 | $this->initConnection(); | 292 | $this->initConnection(); |
291 | } else { | 293 | } else { |
292 | \Yii::error("Failed to open redis DB connection ($connection): $errorNumber - $errorDescription", __CLASS__); | 294 | \Yii::error("Failed to open redis DB connection ($connection): $errorNumber - $errorDescription", __CLASS__); |
@@ -304,7 +306,7 @@ class Connection extends Component | @@ -304,7 +306,7 @@ class Connection extends Component | ||
304 | if ($this->_socket !== false) { | 306 | if ($this->_socket !== false) { |
305 | $connection = ($this->unixSocket ?: $this->hostname . ':' . $this->port) . ', database=' . $this->database; | 307 | $connection = ($this->unixSocket ?: $this->hostname . ':' . $this->port) . ', database=' . $this->database; |
306 | \Yii::trace('Closing DB connection: ' . $connection, __METHOD__); | 308 | \Yii::trace('Closing DB connection: ' . $connection, __METHOD__); |
307 | - //$this->executeCommand('QUIT'); | 309 | + $this->executeCommand('QUIT'); |
308 | stream_socket_shutdown($this->_socket, STREAM_SHUT_RDWR); | 310 | stream_socket_shutdown($this->_socket, STREAM_SHUT_RDWR); |
309 | $this->_socket = null; | 311 | $this->_socket = null; |
310 | } | 312 | } |
-
Please register or login to post a comment