class Predis in Redis 8
Same name in this branch
- 8 src/Lock/Predis.php \Drupal\redis\Lock\Predis
- 8 src/Flood/Predis.php \Drupal\redis\Flood\Predis
- 8 src/Queue/Predis.php \Drupal\redis\Queue\Predis
- 8 src/Client/Predis.php \Drupal\redis\Client\Predis
- 8 src/Cache/Predis.php \Drupal\redis\Cache\Predis
- 8 src/PersistentLock/Predis.php \Drupal\redis\PersistentLock\Predis
Predis cache backend.
Hierarchy
- class \Drupal\redis\Cache\CacheBase implements CacheBackendInterface uses RedisPrefixTrait
- class \Drupal\redis\Cache\Predis
Expanded class hierarchy of Predis
3 string references to 'Predis'
- ClientFactory::getClientInterface in src/
ClientFactory.php - Lazy instantiates client proxy depending on the actual configuration.
- Predis::getName in src/
Client/ Predis.php - Get underlying library name used.
- RedisCacheTagsChecksum::doInvalidateTags in src/
Cache/ RedisCacheTagsChecksum.php - Marks cache items with any of the specified tags as invalid.
File
- src/
Cache/ Predis.php, line 12
Namespace
Drupal\redis\CacheView source
class Predis extends CacheBase {
/**
* @var \Predis\Client
*/
protected $client;
/**
* Creates a Predis cache backend.
*
* @param $bin
* The cache bin for which the object is created.
* @param \Redis $client
* @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
* @param \Drupal\redis\Cache\SerializationInterface $serializer
* The serialization class to use.
*/
public function __construct($bin, \Predis\Client $client, CacheTagsChecksumInterface $checksum_provider, SerializationInterface $serializer) {
parent::__construct($bin, $serializer);
$this->client = $client;
$this->checksumProvider = $checksum_provider;
}
/**
* {@inheritdoc}
*/
public function getMultiple(&$cids, $allow_invalid = FALSE) {
// Avoid an error when there are no cache ids.
if (empty($cids)) {
return [];
}
$return = [];
// Build the list of keys to fetch.
$keys = array_map([
$this,
'getKey',
], $cids);
// Optimize for the common case when only a single cache entry needs to
// be fetched, no pipeline is needed then.
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)),
];
}
// Loop over the cid values to ensure numeric indexes.
foreach (array_values($cids) as $index => $key) {
// Check if a valid result was returned from Redis.
if (isset($result[$index]) && is_array($result[$index])) {
// Check expiration and invalidation and convert into an object.
$item = $this
->expandEntry($result[$index], $allow_invalid);
if ($item) {
$return[$item->cid] = $item;
}
}
}
// Remove fetched cids from the list.
$cids = array_diff($cids, array_keys($return));
return $return;
}
/**
* {@inheritdoc}
*/
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {
$ttl = $this
->getExpiration($expire);
$key = $this
->getKey($cid);
// If the item is already expired, delete it.
if ($ttl <= 0) {
$this
->delete($key);
}
// Build the cache item and save it as a hash array.
$entry = $this
->createEntryHash($cid, $data, $expire, $tags);
$pipe = $this->client
->pipeline();
$pipe
->hmset($key, $entry);
$pipe
->expire($key, $ttl);
$pipe
->execute();
}
/**
* {@inheritdoc}
*/
public function doDeleteMultiple(array $cids) {
if (!empty($cids)) {
$keys = array_map([
$this,
'getKey',
], $cids);
$this->client
->del($keys);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheBackendInterface:: |
constant | Indicates that the item should never be removed unless explicitly deleted. | ||
CacheBase:: |
protected | property | ||
CacheBase:: |
protected | property | The cache tags checksum provider. | |
CacheBase:: |
protected | property | Delayed deletions for deletions during a transaction. | |
CacheBase:: |
protected | property | The last delete timestamp. | |
CacheBase:: |
protected | property | Minimal TTL to use. | |
CacheBase:: |
protected | property | Default TTL for CACHE_PERMANENT items. | |
CacheBase:: |
protected | property | The serialization class to use. | |
CacheBase:: |
protected | function | Create cache entry. | |
CacheBase:: |
public | function |
Deletes an item from the cache. Overrides CacheBackendInterface:: |
|
CacheBase:: |
public | function |
Deletes all cache items in a bin. Overrides CacheBackendInterface:: |
|
CacheBase:: |
public | function |
Deletes multiple items from the cache. Overrides CacheBackendInterface:: |
|
CacheBase:: |
protected | function | Prepares a cached item. | |
CacheBase:: |
public | function |
Performs garbage collection on a cache bin. Overrides CacheBackendInterface:: |
|
CacheBase:: |
public | function |
Returns data from the persistent cache. Overrides CacheBackendInterface:: |
|
CacheBase:: |
protected | function | Calculate the correct expiration time. | |
CacheBase:: |
public | function | Return the key for the given cache key. | |
CacheBase:: |
protected | function | Returns the last delete all timestamp. | |
CacheBase:: |
public | function | Get TTL for CACHE_PERMANENT items. | |
CacheBase:: |
protected | function | Return the key for the tag used to specify the bin of cache-entries. | |
CacheBase:: |
public | function |
Marks a cache item as invalid. Overrides CacheBackendInterface:: |
|
CacheBase:: |
public | function |
Marks all cache items as invalid. Overrides CacheBackendInterface:: |
|
CacheBase:: |
public | function |
Marks cache items as invalid. Overrides CacheBackendInterface:: |
|
CacheBase:: |
constant | Computed keys are let's say around 60 characters length due to key prefixing, which makes 1,000 keys DEL command to be something around 50,000 bytes length: this is huge and may not pass into Redis, let's split this off. Some recommend to… | ||
CacheBase:: |
constant | Latest delete all flush KEY name. | ||
CacheBase:: |
constant | Temporary cache items lifetime is infinite. | ||
CacheBase:: |
constant | Default lifetime for permanent items. Approximatively 1 year. | ||
CacheBase:: |
public | function | Callback to be invoked after a database transaction gets committed. | |
CacheBase:: |
public | function |
Remove a cache bin. Overrides CacheBackendInterface:: |
|
CacheBase:: |
public | function | Set the minimum TTL (unit testing only). | |
CacheBase:: |
public | function |
Store multiple items in the persistent cache. Overrides CacheBackendInterface:: |
|
CacheBase:: |
public | function | Set the permanent TTL. | |
Predis:: |
protected | property |
Overrides CacheBase:: |
|
Predis:: |
public | function |
Execute the deletion. Overrides CacheBase:: |
|
Predis:: |
public | function |
Returns data from the persistent cache when given an array of cache IDs. Overrides CacheBackendInterface:: |
|
Predis:: |
public | function |
Stores data in the persistent cache. Overrides CacheBackendInterface:: |
|
Predis:: |
public | function |
Creates a Predis cache backend. Overrides CacheBase:: |
|
RedisPrefixTrait:: |
protected | property | ||
RedisPrefixTrait:: |
protected | function | Get global default prefix | |
RedisPrefixTrait:: |
protected | function | Get prefix | |
RedisPrefixTrait:: |
public | function | Set prefix |