mirror of
https://github.com/predis/predis.git
synced 2026-08-19 19:12:20 +00:00
Change how network resources are handled internally and also exposed to subclasses.
This commit is contained in:
@@ -9,8 +9,8 @@ use Predis\CommunicationException;
|
||||
use Predis\Commands\ICommand;
|
||||
|
||||
abstract class ConnectionBase implements IConnectionSingle {
|
||||
private $_cachedId;
|
||||
protected $_params, $_initCmds, $_resource;
|
||||
private $_cachedId, $_resource;
|
||||
protected $_params, $_initCmds;
|
||||
|
||||
public function __construct(ConnectionParameters $parameters) {
|
||||
$this->_initCmds = array();
|
||||
@@ -22,7 +22,7 @@ abstract class ConnectionBase implements IConnectionSingle {
|
||||
}
|
||||
|
||||
public function isConnected() {
|
||||
return is_resource($this->_resource);
|
||||
return isset($this->_resource);
|
||||
}
|
||||
|
||||
protected abstract function createResource();
|
||||
@@ -34,6 +34,10 @@ abstract class ConnectionBase implements IConnectionSingle {
|
||||
$this->_resource = $this->createResource();
|
||||
}
|
||||
|
||||
public function disconnect() {
|
||||
unset($this->_resource);
|
||||
}
|
||||
|
||||
public function pushInitCommand(ICommand $command){
|
||||
$this->_initCmds[] = $command;
|
||||
}
|
||||
@@ -50,9 +54,10 @@ abstract class ConnectionBase implements IConnectionSingle {
|
||||
}
|
||||
|
||||
public function getResource() {
|
||||
if (!$this->isConnected()) {
|
||||
$this->connect();
|
||||
if (isset($this->_resource)) {
|
||||
return $this->_resource;
|
||||
}
|
||||
$this->connect();
|
||||
return $this->_resource;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@ class PhpiredisConnection extends ConnectionBase {
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
$this->disconnect();
|
||||
phpiredis_reader_destroy($this->_reader);
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
protected function checkParameters(ConnectionParameters $parameters) {
|
||||
@@ -202,8 +202,8 @@ class PhpiredisConnection extends ConnectionBase {
|
||||
|
||||
public function disconnect() {
|
||||
if ($this->isConnected()) {
|
||||
socket_close($this->_resource);
|
||||
$this->_resource = null;
|
||||
socket_close($this->getResource());
|
||||
parent::disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ class StreamConnection extends ConnectionBase {
|
||||
public function disconnect() {
|
||||
if ($this->isConnected()) {
|
||||
fclose($this->getResource());
|
||||
parent::disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user