public function Redis_Cache_PhpRedis::set in Redis 7.3
Same name and namespace in other branches
- 7 lib/Redis/Cache/PhpRedis.php \Redis_Cache_PhpRedis::set()
- 7.2 lib/Redis/Cache/PhpRedis.php \Redis_Cache_PhpRedis::set()
File
- lib/
Redis/ Cache/ PhpRedis.php, line 81
Class
- Redis_Cache_PhpRedis
- Predis cache backend.
Code
public function set($id, $data, $ttl = null, $volatile = false) {
// Ensure TTL consistency: if the caller gives us an expiry timestamp
// in the past the key will expire now and will never be read.
// Behavior between Predis and PhpRedis seems to change here: when
// setting a negative expire time, PhpRedis seems to ignore the
// command and leave the key permanent.
if (null !== $ttl && $ttl <= 0) {
return;
}
$data['volatile'] = (int) $volatile;
$client = $this
->getClient();
$key = $this
->getKey($id);
$pipe = $client
->multi(Redis::PIPELINE);
$pipe
->hmset($key, $data);
if (null !== $ttl) {
$pipe
->expire($key, $ttl);
}
$pipe
->exec();
}