Files
predis/lib/Predis/Commands/SetMultiple.php
T
Daniele Alessandri c4064e5801 Some commands accepting multiple keys can be hashed if all the keys return the same hash (key tags).
List of the commands affected by this change (based on Redis 2.2):
    MSET, MGET, DEL, BLPOP, BRPOP, RPOPLPUSH, BRPOPLPUSH, SINTER, SINTERSTORE,
    SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, ZINTERSTORE, ZUNIONSTORE.
2011-03-27 12:12:51 +02:00

28 lines
777 B
PHP

<?php
namespace Predis\Commands;
class SetMultiple extends Command {
protected function canBeHashed() {
$args = $this->getArguments();
$keys = array();
for ($i = 0; $i < count($args); $i += 2) {
$keys[] = $args[$i];
}
return $this->checkSameHashForKeys($keys);
}
public function getId() { return 'MSET'; }
public function filterArguments(Array $arguments) {
if (count($arguments) === 1 && is_array($arguments[0])) {
$flattenedKVs = array();
$args = $arguments[0];
foreach ($args as $k => $v) {
$flattenedKVs[] = $k;
$flattenedKVs[] = $v;
}
return $flattenedKVs;
}
return $arguments;
}
}