mirror of
https://github.com/predis/predis.git
synced 2026-10-18 17:55:50 +00:00
Do not extend EVALSHA for ScriptCommand class.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user