You are here

protected function Redis_Path_Predis::saveInHash in Redis 7.2

Same name and namespace in other branches
  1. 7.3 lib/Redis/Path/Predis.php \Redis_Path_Predis::saveInHash()
1 call to Redis_Path_Predis::saveInHash()
Redis_Path_Predis::saveAlias in lib/Redis/Path/Predis.php
Alias is being inserted with the given source

File

lib/Redis/Path/Predis.php, line 12

Class

Redis_Path_Predis
PhpRedis implementation.

Code

protected function saveInHash($key, $hkey, $hvalue) {
  $client = Redis_Client::getClient();
  $value = $client
    ->hget($key, $hkey);
  if ($value === self::VALUE_NULL) {

    // Remove any null values
    $value = null;
  }
  if ($value) {
    $existing = explode(self::VALUE_SEPARATOR, $value);
    if (!in_array($hvalue, $existing)) {

      // Prepend the most recent path to ensure it always be
      // first fetched one
      // @todo Ensure in case of update that its position does
      // not changes (pid ordering in Drupal core)
      $value = $hvalue . self::VALUE_SEPARATOR . $value;
    }
    else {

      // Do nothing on empty value
      $value = null;
    }
  }
  else {
    if (empty($hvalue)) {
      $value = self::VALUE_NULL;
    }
    else {
      $value = $hvalue;
    }
  }
  if (!empty($value)) {
    $client
      ->hset($key, $hkey, $value);
  }

  // Empty value here means that we already got it
}