Do not extend EVALSHA for ScriptCommand class.

This commit is contained in:
Daniele Alessandri
2016-06-09 12:10:39 +02:00
parent 8b466d05df
commit d72a1b5550
3 changed files with 124 additions and 55 deletions
+32 -4
View File
@@ -11,8 +11,6 @@
namespace Predis\Command;
use Predis\Command\Redis\EVALSHA;
/**
* Base class used to implement an higher level abstraction for commands based
* on Lua scripting with EVAL and EVALSHA.
@@ -21,8 +19,16 @@ use Predis\Command\Redis\EVALSHA;
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
abstract class ScriptCommand extends EVALSHA
abstract class ScriptCommand extends Command
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'EVALSHA';
}
/**
* Gets the body of a Lua script.
*
@@ -30,6 +36,16 @@ abstract class ScriptCommand extends EVALSHA
*/
abstract public function getScript();
/**
* Calculates the SHA1 hash of the body of the script.
*
* @return string SHA1 hash.
*/
public function getScriptHash()
{
return sha1($this->getScript());
}
/**
* Specifies the number of arguments that should be considered as keys.
*
@@ -63,12 +79,14 @@ abstract class ScriptCommand extends EVALSHA
$numkeys = count($arguments) + $numkeys;
}
$arguments = array_merge(array(sha1($this->getScript()), (int) $numkeys), $arguments);
$arguments = array_merge(array($this->getScriptHash(), (int) $numkeys), $arguments);
parent::setArguments($arguments);
}
/**
* Returns arguments for EVAL command.
*
* @return array
*/
public function getEvalArguments()
@@ -78,4 +96,14 @@ abstract class ScriptCommand extends EVALSHA
return $arguments;
}
/**
* Returns the equivalent EVAL command as a raw command instance.
*
* @return RawCommand
*/
public function getEvalCommand()
{
return new RawCommand('EVAL', $this->getEvalArguments());
}
}