Predis.php in Redis 8
File
src/Cache/Predis.php
View source
<?php
namespace Drupal\redis\Cache;
use Drupal\Component\Serialization\SerializationInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheTagsChecksumInterface;
class Predis extends CacheBase {
protected $client;
public function __construct($bin, \Predis\Client $client, CacheTagsChecksumInterface $checksum_provider, SerializationInterface $serializer) {
parent::__construct($bin, $serializer);
$this->client = $client;
$this->checksumProvider = $checksum_provider;
}
public function getMultiple(&$cids, $allow_invalid = FALSE) {
if (empty($cids)) {
return [];
}
$return = [];
$keys = array_map([
$this,
'getKey',
], $cids);
if (count($keys) > 1) {
$pipe = $this->client
->pipeline();
foreach ($keys as $key) {
$pipe
->hgetall($key);
}
$result = $pipe
->execute();
}
else {
$result = [
$this->client
->hGetAll(reset($keys)),
];
}
foreach (array_values($cids) as $index => $key) {
if (isset($result[$index]) && is_array($result[$index])) {
$item = $this
->expandEntry($result[$index], $allow_invalid);
if ($item) {
$return[$item->cid] = $item;
}
}
}
$cids = array_diff($cids, array_keys($return));
return $return;
}
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {
$ttl = $this
->getExpiration($expire);
$key = $this
->getKey($cid);
if ($ttl <= 0) {
$this
->delete($key);
}
$entry = $this
->createEntryHash($cid, $data, $expire, $tags);
$pipe = $this->client
->pipeline();
$pipe
->hmset($key, $entry);
$pipe
->expire($key, $ttl);
$pipe
->execute();
}
public function doDeleteMultiple(array $cids) {
if (!empty($cids)) {
$keys = array_map([
$this,
'getKey',
], $cids);
$this->client
->del($keys);
}
}
}