public function setMulti(array $items, $expire = 0)
{
$ttl = $this->ttl($expire);
/*
* Negative ttl behavior isn't properly documented & doesn't always
* appear to treat the value as non-existing. Let's play safe and just
* delete it right away!
*/
if ($ttl < 0) {
$this->deleteMulti(array_keys($items));
return array_fill_keys(array_keys($items), true);
}
if ($ttl === null) {
$success = $this->client->mset($items);
return array_fill_keys(array_keys($items), $success);
}
$this->client->multi();
$this->client->mset($items);
// Redis has no convenient multi-expire method
foreach ($items as $key => $value) {
$this->client->expire($key, $ttl);
}
/* @var bool[] $return */
$result = (array) $this->client->exec();
$return = array();
$keys = array_keys($items);
$success = array_shift($result);
foreach ($result as $i => $value) {
$key = $keys[$i];
$return[$key] = $success && $value;
}
return $return;
}