Scripting abstraction can use negatives to calculate number of keys.

With a negative number Predis will count from the end of the arguments list
to calculate the actual number of keys that will be interpreted as elements
for `KEYS` by the underlying `EVAL` command.
This commit is contained in:
Daniele Alessandri
2012-04-25 11:11:30 +02:00
parent f4c58b926b
commit 5af2b628f1
4 changed files with 99 additions and 12 deletions
+7 -2
View File
@@ -60,8 +60,13 @@ abstract class ScriptedCommand extends ServerEval
*/
protected function filterArguments(Array $arguments)
{
$header = array($this->getScript(), ($keys = $this->getKeysCount()) !== false ? $keys : count($arguments));
if (false !== $numkeys = $this->getKeysCount()) {
$numkeys = $numkeys >= 0 ? $numkeys : count($arguments) + $numkeys;
}
else {
$numkeys = count($arguments);
}
return array_merge($header, $arguments);
return array_merge(array($this->getScript(), $numkeys), $arguments);
}
}