You are here

public function Redis_Cache_Predis::set in Redis 7.3

Same name and namespace in other branches
  1. 7 lib/Redis/Cache/Predis.php \Redis_Cache_Predis::set()
  2. 7.2 lib/Redis/Cache/Predis.php \Redis_Cache_Predis::set()

File

lib/Redis/Cache/Predis.php, line 81

Class

Redis_Cache_Predis
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;
  }
  $key = $this
    ->getKey($id);
  $data['volatile'] = (int) $volatile;
  $pipe = $this
    ->getClient()
    ->pipeline();
  $pipe
    ->hmset($key, $data);
  if (null !== $ttl) {
    $pipe
      ->expire($key, $ttl);
  }
  $pipe
    ->execute();
}