|
@@ -769,8 +769,10 @@ class CommandPipeline {
|
|
class MultiExecBlock {
|
|
class MultiExecBlock {
|
|
private $_initialized, $_discarded, $_insideBlock;
|
|
private $_initialized, $_discarded, $_insideBlock;
|
|
private $_redisClient, $_options, $_commands;
|
|
private $_redisClient, $_options, $_commands;
|
|
|
|
+ private $_supportsWatch;
|
|
|
|
|
|
public function __construct(Client $redisClient, Array $options = null) {
|
|
public function __construct(Client $redisClient, Array $options = null) {
|
|
|
|
+ $this->checkCapabilities($redisClient);
|
|
$this->_initialized = false;
|
|
$this->_initialized = false;
|
|
$this->_discarded = false;
|
|
$this->_discarded = false;
|
|
$this->_insideBlock = false;
|
|
$this->_insideBlock = false;
|
|
@@ -779,6 +781,33 @@ class MultiExecBlock {
|
|
$this->_commands = array();
|
|
$this->_commands = array();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private function checkCapabilities(Client $redisClient) {
|
|
|
|
+ $profile = $redisClient->getProfile();
|
|
|
|
+
|
|
|
|
+ $canMulti = $profile->supportsCommand('multi') &&
|
|
|
|
+ $profile->supportsCommand('exec') &&
|
|
|
|
+ $profile->supportsCommand('discard');
|
|
|
|
+
|
|
|
|
+ $canWatch = $profile->supportsCommand('watch') &&
|
|
|
|
+ $profile->supportsCommand('unwatch');
|
|
|
|
+
|
|
|
|
+ if ($canMulti === false) {
|
|
|
|
+ throw new \Predis\ClientException(
|
|
|
|
+ 'The current profile does not support MULTI, EXEC and DISCARD commands'
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->_supportsWatch = $canWatch;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function isWatchSupported() {
|
|
|
|
+ if ($this->_supportsWatch === false) {
|
|
|
|
+ throw new \Predis\ClientException(
|
|
|
|
+ 'The current profile does not support WATCH and UNWATCH commands'
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private function initialize() {
|
|
private function initialize() {
|
|
if ($this->_initialized === false) {
|
|
if ($this->_initialized === false) {
|
|
if (isset($this->_options['watch'])) {
|
|
if (isset($this->_options['watch'])) {
|
|
@@ -808,6 +837,7 @@ class MultiExecBlock {
|
|
}
|
|
}
|
|
|
|
|
|
public function watch($keys) {
|
|
public function watch($keys) {
|
|
|
|
+ $this->isWatchSupported();
|
|
if ($this->_initialized === true) {
|
|
if ($this->_initialized === true) {
|
|
throw new \Predis\ClientException('WATCH inside MULTI is not allowed');
|
|
throw new \Predis\ClientException('WATCH inside MULTI is not allowed');
|
|
}
|
|
}
|
|
@@ -830,10 +860,8 @@ class MultiExecBlock {
|
|
}
|
|
}
|
|
|
|
|
|
public function unwatch() {
|
|
public function unwatch() {
|
|
- $client = $this->_redisClient;
|
|
|
|
- if (!$client->getProfile()->supportsCommand('unwatch')) {
|
|
|
|
- }
|
|
|
|
- $client->unwatch();
|
|
|
|
|
|
+ $this->isWatchSupported();
|
|
|
|
+ $this->_redisClient->unwatch();
|
|
}
|
|
}
|
|
|
|
|
|
public function discard() {
|
|
public function discard() {
|