Pārlūkot izejas kodu

Deprecate Predis\Client::multiExec().

This method will be replaced by Predis\Client::transaction() in the
next major release of Predis.
Daniele Alessandri 11 gadi atpakaļ
vecāks
revīzija
de02c81398
3 mainītis faili ar 27 papildinājumiem un 1 dzēšanām
  1. 1 1
      examples/TransactionWithCAS.php
  2. 16 0
      lib/Predis/Client.php
  3. 10 0
      tests/Predis/ClientTest.php

+ 1 - 1
examples/MultiExecTransactionsWithCAS.php → 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)) {

+ 16 - 0
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.
      *

+ 10 - 0
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
      */