ScriptedCommand.php 911 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace Predis\Commands;
  3. abstract class ScriptedCommand extends ServerEval {
  4. public abstract function getScript();
  5. protected function keysCount() {
  6. // The default behaviour is to use the first argument as the only value
  7. // for KEYS and the rest of the arguments (if any) for ARGV. When -1 is
  8. // returned, all the arguments are considered as values for KEYS.
  9. return 1;
  10. }
  11. protected function filterArguments(Array $arguments) {
  12. if (($keys = $this->keysCount()) === -1) {
  13. $keys = count($arguments);
  14. }
  15. return array_merge(array($this->getScript(), $keys), $arguments);
  16. }
  17. protected function getKeys() {
  18. $arguments = $this->getArguments();
  19. if (($keys = $this->keysCount()) === -1) {
  20. return array_slice($arguments, 2);
  21. }
  22. return array_slice($arguments, 2, $keys);
  23. }
  24. }