You are here

protected function Redis_Cache_PhpRedis::clearWithoutEval in Redis 7.2

1 call to Redis_Cache_PhpRedis::clearWithoutEval()
Redis_Cache_PhpRedis::clear in lib/Redis/Cache/PhpRedis.php
Expires data from the cache.

File

lib/Redis/Cache/PhpRedis.php, line 162

Class

Redis_Cache_PhpRedis
Predis cache backend.

Code

protected function clearWithoutEval($cid = NULL, $wildcard = FALSE) {
  $keys = array();
  $skey = $this
    ->getKey(Redis_Cache_Base::TEMP_SET);
  $client = Redis_Client::getClient();
  if (NULL === $cid) {
    switch ($this
      ->getClearMode()) {

      // One and only case of early return.
      case Redis_Cache_Base::FLUSH_NOTHING:
        return;

      // Default behavior.
      case Redis_Cache_Base::FLUSH_TEMPORARY:
        if (Redis_Cache_Base::LIFETIME_INFINITE == variable_get('cache_lifetime', Redis_Cache_Base::LIFETIME_DEFAULT)) {
          $keys[] = $skey;
          foreach ($client
            ->smembers($skey) as $tcid) {
            $keys[] = $this
              ->getKey($tcid);
          }
        }
        break;

      // Fallback on most secure mode: flush full bin.
      default:
      case Redis_Cache_Base::FLUSH_ALL:
        $keys[] = $skey;
        $cid = '*';
        $wildcard = true;
        break;
    }
  }
  if ('*' !== $cid && $wildcard) {

    // Prefix flush.
    $remoteKeys = $client
      ->keys($this
      ->getKey($cid . '*'));

    // PhpRedis seems to suffer of some bugs.
    if (!empty($remoteKeys) && is_array($remoteKeys)) {
      $keys = array_merge($keys, $remoteKeys);
    }
  }
  else {
    if ('*' === $cid) {

      // Full bin flush.
      $remoteKeys = $client
        ->keys($this
        ->getKey('*'));

      // PhpRedis seems to suffer of some bugs.
      if (!empty($remoteKeys) && is_array($remoteKeys)) {
        $keys = array_merge($keys, $remoteKeys);
      }
    }
    else {
      if (empty($keys) && !empty($cid)) {

        // Single key drop.
        $keys[] = $key = $this
          ->getKey($cid);
        $client
          ->srem($skey, $key);
      }
    }
  }
  if (!empty($keys)) {
    if (count($keys) < Redis_Cache_Base::KEY_THRESHOLD) {
      $client
        ->del($keys);
    }
    else {
      $pipe = $client
        ->multi(Redis::PIPELINE);
      do {
        $buffer = array_splice($keys, 0, Redis_Cache_Base::KEY_THRESHOLD);
        $pipe
          ->del($buffer);
      } while (!empty($keys));
      $pipe
        ->exec();
    }
  }
}