Kaynağa Gözat

Rename command class for scripting to Predis\Command\ScriptCommand.

We also changed our wording to indentify this kind of abstraction so
instead of using "scripted commands" (kind of broken English) we now
use "scriptable commands".
Daniele Alessandri 11 yıl önce
ebeveyn
işleme
09895f27bf

+ 4 - 1
CHANGELOG.md

@@ -36,7 +36,10 @@ v0.9.0 (201x-xx-xx)
     - `fire-and-forget`: returns a pipeline that does not read back responses
       (class: `Predis\Pipeline\FireAndForget`).
 
-- The base abstract command class has been renamed to Predis\Command\Command.
+- The two base abstract command classes have been renamed in the following way:
+
+    - `Predis\Command\AbstractCommand` is now `Predis\Command\Command`
+    - `Predis\Command\ScriptedCommand` is now `Predis\Command\ScriptCommand`
 
 - Most classes and interfaces in the `Predis\Protocol` namespace have been moved
   or renamed while rationalizing the whole API of external protocol processors.

+ 4 - 4
README.md

@@ -177,14 +177,14 @@ $redis->newcmd();
 
 ### Abstraction for handling Lua scripts as plain Redis commands ###
 
-A scripted command in Predis is an abstraction for [Lua scripting](http://redis.io/commands/eval)
+A scriptable command in Predis is an abstraction for [Lua scripting](http://redis.io/commands/eval)
 in Redis >= 2.6 allowing to use a Lua script as if it was a Redis command registered in the profile
-used by the client. Internally scripted commands use [EVALSHA](http://redis.io/commands/evalsha) to
-refer to a Lua script by its SHA1 hash in order to save bandwidth, but they are capable of falling
+used by the client. Internally scriptable commands use [EVALSHA](http://redis.io/commands/evalsha) to
+identify a Lua script by its SHA1 hash in order to save bandwidth, but they are capable of falling
 back to [EVAL](http://redis.io/commands/eval) when needed:
 
 ```php
-class ListPushRandomValue extends Predis\Command\ScriptedCommand
+class ListPushRandomValue extends Predis\Command\ScriptCommand
 {
     public function getKeysCount()
     {

+ 11 - 11
examples/MasterSlaveReplicationComplex.php

@@ -11,23 +11,23 @@
 
 require 'SharedConfigurations.php';
 
-// Predis allows to set Lua scripts as read-only operations in the context of
-// replication. This works for both EVAL and EVALSHA and also for the client-side
-// abstraction built upon them (Predis\Command\ScriptedCommand). This example
-// shows a slightly more complex configuration that injects a new scripted command
-// in the server profile used by the new client instance and marks it marks it as
-// a read-only operation for replication so that it will be executed on slaves.
-
-use Predis\Command\ScriptedCommand;
+// Predis allows to set Lua scripts as read-only operations for replication.
+// This works for both EVAL and EVALSHA and also for the client-side abstraction
+// built upon them (Predis\Command\ScriptCommand). This example shows a slightly
+// more complex configuration that injects a new script command in the server
+// profile used by the new client instance and marks it marks it as a read-only
+// operation for replication so that it will be executed on slaves.
+
+use Predis\Command\ScriptCommand;
 use Predis\Connection\MasterSlaveReplication;
 use Predis\Replication\ReplicationStrategy;
 
 // ------------------------------------------------------------------------- //
 
-// Define a new scripted command that returns all the fields
-// of a variable number of hashes with a single roundtrip.
+// Define a new script command that returns all the fields of a variable number
+// of hashes with a single roundtrip.
 
-class HashMultipleGetAll extends ScriptedCommand {
+class HashMultipleGetAll extends ScriptCommand {
     const BODY = <<<EOS
 local hashes = {}
 for _, key in pairs(KEYS) do

+ 7 - 6
examples/ServerSideScripting.php

@@ -13,14 +13,15 @@ require 'SharedConfigurations.php';
 
 // This example will not work with versions of Redis < 2.6.
 //
-// Additionally to the EVAL command defined in the current development profile, the new
-// Predis\Command\ScriptedCommand base class can be used to build an higher abstraction
-// for our "scripted" commands so that they will appear just like any other command on
-// the client-side. This is a quick example used to implement INCREX.
+// Additionally to the EVAL command defined in the current development profile,
+// the Predis\Command\ScriptCommand class can be used to build an higher level
+// abstraction for "scriptable" commands so that they will appear just like any
+// other command on the client-side. This is a quick example used to implement
+// INCREX.
 
-use Predis\Command\ScriptedCommand;
+use Predis\Command\ScriptCommand;
 
-class IncrementExistingKeysBy extends ScriptedCommand
+class IncrementExistingKeysBy extends ScriptCommand
 {
     public function getKeysCount()
     {

+ 2 - 2
lib/Predis/Client.php

@@ -14,7 +14,7 @@ namespace Predis;
 use InvalidArgumentException;
 use UnexpectedValueException;
 use Predis\Command\CommandInterface;
-use Predis\Command\ScriptedCommand;
+use Predis\Command\ScriptCommand;
 use Predis\Configuration;
 use Predis\Connection\AggregatedConnectionInterface;
 use Predis\Connection\ConnectionInterface;
@@ -299,7 +299,7 @@ class Client implements ClientInterface
      */
     protected function onResponseError(CommandInterface $command, Response\ErrorInterface $response)
     {
-        if ($command instanceof ScriptedCommand && $response->getErrorType() === 'NOSCRIPT') {
+        if ($command instanceof ScriptCommand && $response->getErrorType() === 'NOSCRIPT') {
             $eval = $this->createCommand('eval');
             $eval->setRawArguments($command->getEvalArguments());
 

+ 2 - 2
lib/Predis/Cluster/PredisStrategy.php

@@ -13,7 +13,7 @@ namespace Predis\Cluster;
 
 use Predis\Cluster\Hash\HashGeneratorInterface;
 use Predis\Command\CommandInterface;
-use Predis\Command\ScriptedCommand;
+use Predis\Command\ScriptCommand;
 
 /**
  * Default class used by Predis for client-side sharding to calculate
@@ -300,7 +300,7 @@ class PredisStrategy implements StrategyInterface
      */
     protected function getKeyFromScriptingCommands(CommandInterface $command)
     {
-        if ($command instanceof ScriptedCommand) {
+        if ($command instanceof ScriptCommand) {
             $keys = $command->getKeys();
         } else {
             $keys = array_slice($args = $command->getArguments(), 2, $args[1]);

+ 2 - 2
lib/Predis/Cluster/RedisStrategy.php

@@ -12,7 +12,7 @@
 namespace Predis\Cluster;
 
 use Predis\Command\CommandInterface;
-use Predis\Command\ScriptedCommand;
+use Predis\Command\ScriptCommand;
 
 /**
  * Default class used by Predis to calculate hashes out of keys of
@@ -250,7 +250,7 @@ class RedisStrategy implements StrategyInterface
      */
     protected function getKeyFromScriptingCommands(CommandInterface $command)
     {
-        if ($command instanceof ScriptedCommand) {
+        if ($command instanceof ScriptCommand) {
             $keys = $command->getKeys();
         } else {
             $keys = array_slice($args = $command->getArguments(), 2, $args[1]);

+ 2 - 2
lib/Predis/Command/ScriptedCommand.php → lib/Predis/Command/ScriptCommand.php

@@ -13,12 +13,12 @@ namespace Predis\Command;
 
 /**
  * Base class used to implement an higher level abstraction for "virtual"
- * commands based on EVAL.
+ * commands for Lua scripting based on EVAL and EVALSHA.
  *
  * @link http://redis.io/commands/eval
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-abstract class ScriptedCommand extends ServerEvalSHA
+abstract class ScriptCommand extends ServerEvalSHA
 {
     /**
      * Gets the body of a Lua script.

+ 2 - 2
tests/Predis/ClientTest.php

@@ -726,9 +726,9 @@ class ClientTest extends StandardTestCase
     /**
      * @group disconnected
      */
-    public function testClientResendScriptedCommandUsingEvalOnNoScriptErrors()
+    public function testClientResendScriptCommandUsingEvalOnNoScriptErrors()
     {
-        $command = $this->getMockForAbstractClass('Predis\Command\ScriptedCommand', array(), '', true, true, true, array('parseResponse'));
+        $command = $this->getMockForAbstractClass('Predis\Command\ScriptCommand', array(), '', true, true, true, array('parseResponse'));
         $command->expects($this->once())
                 ->method('getScript')
                 ->will($this->returnValue('return redis.call(\'exists\', KEYS[1])'));

+ 4 - 4
tests/Predis/Cluster/PredisStrategyTest.php

@@ -153,7 +153,7 @@ class PredisStrategyTest extends StandardTestCase
     /**
      * @group disconnected
      */
-    public function testKeysForScriptCommand()
+    public function testKeysForEvalCommand()
     {
         $strategy = $this->getClusterStrategy();
         $profile = Profile\Factory::getDevelopment();
@@ -168,12 +168,12 @@ class PredisStrategyTest extends StandardTestCase
     /**
      * @group disconnected
      */
-    public function testKeysForScriptedCommand()
+    public function testKeysForScriptCommand()
     {
         $strategy = $this->getClusterStrategy();
         $arguments = array('{key}:1', '{key}:2', 'value1', 'value2');
 
-        $command = $this->getMock('Predis\Command\ScriptedCommand', array('getScript', 'getKeysCount'));
+        $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
         $command->expects($this->once())
                 ->method('getScript')
                 ->will($this->returnValue('return true'));
@@ -182,7 +182,7 @@ class PredisStrategyTest extends StandardTestCase
                 ->will($this->returnValue(2));
         $command->setArguments($arguments);
 
-        $this->assertNotNull($strategy->getHash($command), "Scripted Command [{$command->getId()}]");
+        $this->assertNotNull($strategy->getHash($command), "Script Command [{$command->getId()}]");
     }
 
     /**

+ 4 - 4
tests/Predis/Cluster/RedisStrategyTest.php

@@ -162,7 +162,7 @@ class RedisStrategyTest extends StandardTestCase
     /**
      * @group disconnected
      */
-    public function testKeysForScriptCommand()
+    public function testKeysForEvalCommand()
     {
         $strategy = $this->getClusterStrategy();
         $profile = Profile\Factory::getDevelopment();
@@ -177,12 +177,12 @@ class RedisStrategyTest extends StandardTestCase
     /**
      * @group disconnected
      */
-    public function testKeysForScriptedCommand()
+    public function testKeysForScriptCommand()
     {
         $strategy = $this->getClusterStrategy();
         $arguments = array('key:1', 'value1');
 
-        $command = $this->getMock('Predis\Command\ScriptedCommand', array('getScript', 'getKeysCount'));
+        $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
         $command->expects($this->once())
                 ->method('getScript')
                 ->will($this->returnValue('return true'));
@@ -191,7 +191,7 @@ class RedisStrategyTest extends StandardTestCase
                 ->will($this->returnValue(1));
         $command->setArguments($arguments);
 
-        $this->assertNotNull($strategy->getHash($command), "Scripted Command [{$command->getId()}]");
+        $this->assertNotNull($strategy->getHash($command), "Script Command [{$command->getId()}]");
     }
 
     /**

+ 8 - 8
tests/Predis/Command/ScriptedCommandTest.php

@@ -16,7 +16,7 @@ use PHPUnit_Framework_TestCase as StandardTestCase;
 /**
  * @group realm-scripting
  */
-class ScriptedCommandTest extends StandardTestCase
+class ScriptCommandTest extends StandardTestCase
 {
     const LUA_SCRIPT = 'return { KEYS[1], KEYS[2], ARGV[1], ARGV[2] }';
     const LUA_SCRIPT_SHA1 = '6e07f61f502e36d123fe28523076af588f5c315e';
@@ -28,7 +28,7 @@ class ScriptedCommandTest extends StandardTestCase
     {
         $arguments = array('key1', 'key2', 'value1', 'value2');
 
-        $command = $this->getMock('Predis\Command\ScriptedCommand', array('getScript', 'getKeysCount'));
+        $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
         $command->expects($this->once())
                 ->method('getScript')
                 ->will($this->returnValue(self::LUA_SCRIPT));
@@ -48,7 +48,7 @@ class ScriptedCommandTest extends StandardTestCase
     {
         $arguments = array('key1', 'key2', 'value1', 'value2');
 
-        $command = $this->getMock('Predis\Command\ScriptedCommand', array('getScript', 'getKeysCount'));
+        $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
         $command->expects($this->once())
                 ->method('getScript')
                 ->will($this->returnValue(self::LUA_SCRIPT));
@@ -67,7 +67,7 @@ class ScriptedCommandTest extends StandardTestCase
     {
         $arguments = array('value1', 'value2', 'value3');
 
-        $command = $this->getMock('Predis\Command\ScriptedCommand', array('getScript', 'getKeysCount'));
+        $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
         $command->expects($this->once())
                 ->method('getScript')
                 ->will($this->returnValue(self::LUA_SCRIPT));
@@ -86,7 +86,7 @@ class ScriptedCommandTest extends StandardTestCase
     {
         $arguments = array('key1', 'key2', 'value1', 'value2');
 
-        $command = $this->getMock('Predis\Command\ScriptedCommand', array('getScript', 'getKeysCount'));
+        $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
         $command->expects($this->once())
                 ->method('getScript')
                 ->will($this->returnValue(self::LUA_SCRIPT));
@@ -105,7 +105,7 @@ class ScriptedCommandTest extends StandardTestCase
     {
         $arguments = array('value1', 'value2', 'value3');
 
-        $command = $this->getMock('Predis\Command\ScriptedCommand', array('getScript', 'getKeysCount'));
+        $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
         $command->expects($this->once())
                 ->method('getScript')
                 ->will($this->returnValue(self::LUA_SCRIPT));
@@ -124,7 +124,7 @@ class ScriptedCommandTest extends StandardTestCase
     {
         $arguments = array('key1', 'key2', 'value1', 'value2');
 
-        $command = $this->getMock('Predis\Command\ScriptedCommand', array('getScript', 'getKeysCount'));
+        $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
         $command->expects($this->once())
                 ->method('getScript')
                 ->will($this->returnValue(self::LUA_SCRIPT));
@@ -143,7 +143,7 @@ class ScriptedCommandTest extends StandardTestCase
     {
         $arguments = array('key1', 'key2', 'value1', 'value2');
 
-        $command = $this->getMock('Predis\Command\ScriptedCommand', array('getScript', 'getKeysCount'));
+        $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
         $command->expects($this->once())
                 ->method('getScript')
                 ->will($this->returnValue(self::LUA_SCRIPT));

+ 4 - 4
tests/Predis/Replication/ReplicationStrategyTest.php

@@ -190,11 +190,11 @@ class ReplicationStrategyTest extends StandardTestCase
     /**
      * @group disconnected
      */
-    public function testSetLuaScriptAsReadOperationWorksWithScriptedCommand()
+    public function testSetLuaScriptAsReadOperationWorksWithScriptCommand()
     {
         $strategy = new ReplicationStrategy();
 
-        $command = $this->getMock('Predis\Command\ScriptedCommand', array('getScript'));
+        $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript'));
         $command->expects($this->any())
                 ->method('getScript')
                 ->will($this->returnValue($script = 'return true'));
@@ -213,11 +213,11 @@ class ReplicationStrategyTest extends StandardTestCase
     /**
      * @group disconnected
      */
-    public function testSetLuaScriptAsReadOperationWorksWithScriptedCommandAndCallableCheck()
+    public function testSetLuaScriptAsReadOperationWorksWithScriptCommandAndCallableCheck()
     {
         $strategy = new ReplicationStrategy();
 
-        $command = $this->getMock('Predis\Command\ScriptedCommand', array('getScript'));
+        $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript'));
         $command->expects($this->any())
                 ->method('getScript')
                 ->will($this->returnValue($script = 'return true'));