mirror of
https://github.com/predis/predis.git
synced 2026-09-07 00:43:47 +00:00
Adopt more consistent behaviours for \Predis\MultiExecBlock.
This commit is contained in:
+32
-2
@@ -767,13 +767,15 @@ class CommandPipeline {
|
||||
}
|
||||
|
||||
class MultiExecBlock {
|
||||
private $_redisClient, $_commands, $_initialized, $_discarded, $_options;
|
||||
private $_initialized, $_discarded, $_insideBlock;
|
||||
private $_redisClient, $_options, $_commands;
|
||||
|
||||
public function __construct(Client $redisClient, Array $options = null) {
|
||||
$this->_initialized = false;
|
||||
$this->_options = $options ?: array();
|
||||
$this->_discarded = false;
|
||||
$this->_insideBlock = false;
|
||||
$this->_redisClient = $redisClient;
|
||||
$this->_options = $options ?: array();
|
||||
$this->_commands = array();
|
||||
}
|
||||
|
||||
@@ -788,6 +790,10 @@ class MultiExecBlock {
|
||||
}
|
||||
}
|
||||
|
||||
private function setInsideBlock($value) {
|
||||
$this->_insideBlock = $value;
|
||||
}
|
||||
|
||||
public function __call($method, $arguments) {
|
||||
$this->initialize();
|
||||
$command = $this->_redisClient->createCommand($method, $arguments);
|
||||
@@ -819,6 +825,17 @@ class MultiExecBlock {
|
||||
return $reply;
|
||||
}
|
||||
|
||||
public function multi() {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
public function unwatch() {
|
||||
$client = $this->_redisClient;
|
||||
if (!$client->getProfile()->supportsCommand('unwatch')) {
|
||||
}
|
||||
$client->unwatch();
|
||||
}
|
||||
|
||||
public function discard() {
|
||||
$this->_redisClient->discard();
|
||||
$this->_commands = array();
|
||||
@@ -826,7 +843,17 @@ class MultiExecBlock {
|
||||
$this->_discarded = true;
|
||||
}
|
||||
|
||||
public function exec() {
|
||||
return $this->execute();
|
||||
}
|
||||
|
||||
public function execute($block = null) {
|
||||
if ($this->_insideBlock === true) {
|
||||
throw new \Predis\ClientException(
|
||||
"Cannot invoke 'execute' or 'exec' inside an active client transaction block"
|
||||
);
|
||||
}
|
||||
|
||||
if ($block && !is_callable($block)) {
|
||||
throw new \InvalidArgumentException('Argument passed must be a callable object');
|
||||
}
|
||||
@@ -836,7 +863,9 @@ class MultiExecBlock {
|
||||
|
||||
try {
|
||||
if ($block !== null) {
|
||||
$this->setInsideBlock(true);
|
||||
$block($this);
|
||||
$this->setInsideBlock(false);
|
||||
}
|
||||
|
||||
if ($this->_discarded === true) {
|
||||
@@ -863,6 +892,7 @@ class MultiExecBlock {
|
||||
}
|
||||
}
|
||||
catch (\Exception $exception) {
|
||||
$this->setInsideBlock(false);
|
||||
$blockException = $exception;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user