From de02c813983e79f558c37858c6a7941ad5038802 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 9 Nov 2013 19:28:40 +0100 Subject: [PATCH] Deprecate Predis\Client::multiExec(). This method will be replaced by Predis\Client::transaction() in the next major release of Predis. --- ...actionsWithCAS.php => TransactionWithCAS.php} | 2 +- lib/Predis/Client.php | 16 ++++++++++++++++ tests/Predis/ClientTest.php | 10 ++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) rename examples/{MultiExecTransactionsWithCAS.php => TransactionWithCAS.php} (95%) diff --git a/examples/MultiExecTransactionsWithCAS.php b/examples/TransactionWithCAS.php similarity index 95% rename from examples/MultiExecTransactionsWithCAS.php rename to examples/TransactionWithCAS.php index 6450ab81..785a9db5 100644 --- a/examples/MultiExecTransactionsWithCAS.php +++ b/examples/TransactionWithCAS.php @@ -33,7 +33,7 @@ function zpop($client, $key) // which the client bails out with an exception. ); - $client->multiExec($options, function ($tx) use ($key, &$element) { + $client->transaction($options, function ($tx) use ($key, &$element) { @list($element) = $tx->zrange($key, 0, 0); if (isset($element)) { diff --git a/lib/Predis/Client.php b/lib/Predis/Client.php index 6b4967ed..3a28f8e2 100644 --- a/lib/Predis/Client.php +++ b/lib/Predis/Client.php @@ -369,6 +369,10 @@ class Client implements ClientInterface * Creates a new transaction context and returns it, or returns the results of * a transaction executed inside the optionally provided callable object. * + * @deprecated You should start using the new Client::transaction() method + * as it will replace Client::multiExec() in the next major + * version of the library. + * * @param mixed $arg,... Options for the context, a callable object, or both. * @return MultiExecContext|array */ @@ -377,6 +381,18 @@ class Client implements ClientInterface return $this->sharedInitializer(func_get_args(), 'initMultiExec'); } + /** + * Creates a new transaction context and returns it, or returns the results of + * a transaction executed inside the optionally provided callable object. + * + * @param mixed $arg,... Options for the context, a callable object, or both. + * @return MultiExecContext|array + */ + public function transaction(/* arguments */) + { + return $this->sharedInitializer(func_get_args(), 'initMultiExec'); + } + /** * Transaction context initializer. * diff --git a/tests/Predis/ClientTest.php b/tests/Predis/ClientTest.php index 50d78d08..0338f1b2 100644 --- a/tests/Predis/ClientTest.php +++ b/tests/Predis/ClientTest.php @@ -654,6 +654,16 @@ class ClientTest extends StandardTestCase $this->assertInstanceOf('Predis\Transaction\MultiExecContext', $client->multiExec()); } + /** + * @group disconnected + */ + public function testMethodTransactionIsAliasForMethodMultiExec() + { + $client = new Client(); + + $this->assertInstanceOf('Predis\Transaction\MultiExecContext', $client->transaction()); + } + /** * @group disconnected */