mirror of
https://github.com/predis/predis.git
synced 2026-08-30 12:15:03 +00:00
Merge branch 'v0.9/rename-transaction-class'
This commit is contained in:
@@ -25,7 +25,7 @@ use Predis\Pipeline\PipelineContext;
|
||||
use Predis\Profile\ServerProfile;
|
||||
use Predis\PubSub;
|
||||
use Predis\Response;
|
||||
use Predis\Transaction\MultiExecContext;
|
||||
use Predis\Transaction;
|
||||
|
||||
/**
|
||||
* Client class used for connecting and executing commands on Redis.
|
||||
@@ -391,7 +391,7 @@ class Client implements ClientInterface
|
||||
* of a transaction executed inside the optionally provided callable object.
|
||||
*
|
||||
* @param mixed $arg,... Options for the context, or a callable, or both.
|
||||
* @return MultiExecContext|array
|
||||
* @return Transaction\MultiExec|array
|
||||
*/
|
||||
public function transaction(/* arguments */)
|
||||
{
|
||||
@@ -403,11 +403,11 @@ class Client implements ClientInterface
|
||||
*
|
||||
* @param array $options Options for the context.
|
||||
* @param mixed $callable Optional callable used to execute the context.
|
||||
* @return MultiExecContext|array
|
||||
* @return Transaction\MultiExec|array
|
||||
*/
|
||||
protected function createTransaction(Array $options = null, $callable = null)
|
||||
{
|
||||
$transaction = new MultiExecContext($this, $options);
|
||||
$transaction = new Transaction\MultiExec($this, $options);
|
||||
|
||||
if (isset($callable)) {
|
||||
return $transaction->execute($callable);
|
||||
|
||||
@@ -23,11 +23,11 @@ class AbortedMultiExecException extends PredisException
|
||||
private $transaction;
|
||||
|
||||
/**
|
||||
* @param MultiExecContext $transaction Transaction that generated the exception.
|
||||
* @param MultiExec $transaction Transaction that generated the exception.
|
||||
* @param string $message Error message.
|
||||
* @param int $code Error code.
|
||||
*/
|
||||
public function __construct(MultiExecContext $transaction, $message, $code = null)
|
||||
public function __construct(MultiExec $transaction, $message, $code = null)
|
||||
{
|
||||
parent::__construct($message, $code);
|
||||
$this->transaction = $transaction;
|
||||
@@ -36,7 +36,7 @@ class AbortedMultiExecException extends PredisException
|
||||
/**
|
||||
* Returns the transaction that generated the exception.
|
||||
*
|
||||
* @return MultiExecContext
|
||||
* @return MultiExec
|
||||
*/
|
||||
public function getTransaction()
|
||||
{
|
||||
|
||||
+15
-11
@@ -28,7 +28,7 @@ use Predis\Protocol\ProtocolException;
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
class MultiExecContext implements BasicClientInterface, ExecutableContextInterface
|
||||
class MultiExec implements BasicClientInterface, ExecutableContextInterface
|
||||
{
|
||||
const STATE_RESET = 0; // 0b00000
|
||||
const STATE_INITIALIZED = 1; // 0b00001
|
||||
@@ -45,8 +45,8 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa
|
||||
protected $commands;
|
||||
|
||||
/**
|
||||
* @param ClientInterface $client Client instance used by the context.
|
||||
* @param array $options Options for the context initialization.
|
||||
* @param ClientInterface $client Client instance used by the transaction.
|
||||
* @param array $options Initialization options.
|
||||
*/
|
||||
public function __construct(ClientInterface $client, Array $options = null)
|
||||
{
|
||||
@@ -109,20 +109,24 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa
|
||||
|
||||
/**
|
||||
* Checks if the passed client instance satisfies the required conditions
|
||||
* needed to initialize a transaction context.
|
||||
* needed to initialize the transaction object.
|
||||
*
|
||||
* @param ClientInterface $client Client instance used by the context.
|
||||
* @param ClientInterface $client Client instance used by the transaction object.
|
||||
*/
|
||||
private function checkCapabilities(ClientInterface $client)
|
||||
{
|
||||
if ($client->getConnection() instanceof AggregatedConnectionInterface) {
|
||||
throw new NotSupportedException('Cannot initialize a MULTI/EXEC context when using aggregated connections');
|
||||
throw new NotSupportedException(
|
||||
'Cannot initialize a MULTI/EXEC transaction when using aggregated connections'
|
||||
);
|
||||
}
|
||||
|
||||
$profile = $client->getProfile();
|
||||
|
||||
if ($profile->supportsCommands(array('multi', 'exec', 'discard')) === false) {
|
||||
throw new NotSupportedException('The current profile does not support MULTI, EXEC and DISCARD');
|
||||
throw new NotSupportedException(
|
||||
'The current profile does not support MULTI, EXEC and DISCARD'
|
||||
);
|
||||
}
|
||||
|
||||
$this->canWatch = $profile->supportsCommands(array('watch', 'unwatch'));
|
||||
@@ -242,7 +246,7 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa
|
||||
/**
|
||||
* Finalizes the transaction on the server by executing MULTI on the server.
|
||||
*
|
||||
* @return MultiExecContext
|
||||
* @return MultiExec
|
||||
*/
|
||||
public function multi()
|
||||
{
|
||||
@@ -259,7 +263,7 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa
|
||||
/**
|
||||
* Executes UNWATCH.
|
||||
*
|
||||
* @return MultiExecContext
|
||||
* @return MultiExec
|
||||
*/
|
||||
public function unwatch()
|
||||
{
|
||||
@@ -274,7 +278,7 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa
|
||||
* Resets a transaction by UNWATCHing the keys that are being WATCHed and
|
||||
* DISCARDing the pending commands that have been already sent to the server.
|
||||
*
|
||||
* @return MultiExecContext
|
||||
* @return MultiExec
|
||||
*/
|
||||
public function discard()
|
||||
{
|
||||
@@ -398,7 +402,7 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes the current transaction context to a callable block for execution.
|
||||
* Passes the current transaction object to a callable block for execution.
|
||||
*
|
||||
* @param mixed $callable Callback.
|
||||
*/
|
||||
@@ -688,23 +688,23 @@ class ClientTest extends StandardTestCase
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testTransactionWithoutArgumentsReturnsMultiExecContext()
|
||||
public function testTransactionWithoutArgumentsReturnsMultiExec()
|
||||
{
|
||||
$client = new Client();
|
||||
|
||||
$this->assertInstanceOf('Predis\Transaction\MultiExecContext', $client->transaction());
|
||||
$this->assertInstanceOf('Predis\Transaction\MultiExec', $client->transaction());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testTransactionWithArrayReturnsMultiExecContextWithOptions()
|
||||
public function testTransactionWithArrayReturnsTransactionMultiExecWithOptions()
|
||||
{
|
||||
$options = array('cas' => true, 'retry' => 3);
|
||||
|
||||
$client = new Client();
|
||||
|
||||
$this->assertInstanceOf('Predis\Transaction\MultiExecContext', $tx = $client->transaction($options));
|
||||
$this->assertInstanceOf('Predis\Transaction\MultiExec', $tx = $client->transaction($options));
|
||||
|
||||
$reflection = new \ReflectionProperty($tx, 'options');
|
||||
$reflection->setAccessible(true);
|
||||
|
||||
@@ -26,7 +26,7 @@ class AbortedMultiExecExceptionTest extends StandardTestCase
|
||||
public function testExceptionClass()
|
||||
{
|
||||
$client = new Client();
|
||||
$transaction = new MultiExecContext($client);
|
||||
$transaction = new MultiExec($client);
|
||||
$exception = new AbortedMultiExecException($transaction, 'ABORTED');
|
||||
|
||||
$this->assertInstanceOf('Predis\PredisException', $exception);
|
||||
|
||||
+6
-6
@@ -20,7 +20,7 @@ use Predis\Response;
|
||||
/**
|
||||
* @group realm-transaction
|
||||
*/
|
||||
class MultiExecContextTest extends StandardTestCase
|
||||
class MultiExecTest extends StandardTestCase
|
||||
{
|
||||
/**
|
||||
* @group disconnected
|
||||
@@ -31,7 +31,7 @@ class MultiExecContextTest extends StandardTestCase
|
||||
{
|
||||
$connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
|
||||
$client = new Client($connection, array('profile' => '1.2'));
|
||||
$tx = new MultiExecContext($client);
|
||||
$tx = new MultiExec($client);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ class MultiExecContextTest extends StandardTestCase
|
||||
{
|
||||
$connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
|
||||
$client = new Client($connection, array('profile' => '2.0'));
|
||||
$tx = new MultiExecContext($client, array('options' => 'cas'));
|
||||
$tx = new MultiExec($client, array('options' => 'cas'));
|
||||
|
||||
$tx->watch('foo');
|
||||
}
|
||||
@@ -645,18 +645,18 @@ class MultiExecContextTest extends StandardTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a mocked instance of Predis\Transaction\MultiExecContext using
|
||||
* Returns a mocked instance of Predis\Transaction\MultiExec using
|
||||
* the specified callback to return values from the executeCommand method
|
||||
* of the underlying connection.
|
||||
*
|
||||
* @param \Closure $executeCallback
|
||||
* @return MultiExecContext
|
||||
* @return MultiExec
|
||||
*/
|
||||
protected function getMockedTransaction($executeCallback, $options = array())
|
||||
{
|
||||
$connection = $this->getMockedConnection($executeCallback);
|
||||
$client = new Client($connection);
|
||||
$transaction = new MultiExecContext($client, $options);
|
||||
$transaction = new MultiExec($client, $options);
|
||||
|
||||
return $transaction;
|
||||
}
|
||||
Reference in New Issue
Block a user