cache/predis-adapter
PSR-6 cache pool implementation backed by Predis (Redis) from the PHP Cache organization. Create a Predis\Client and wrap it in PredisCachePool for fast, standards-compliant caching with shared features like tagging and hierarchy support.
Illuminate\Cache\CacheManager). It can be registered as a custom cache driver without disrupting existing PSR-6-compliant code.Cache::tags()), enabling granular cache invalidation by tags (useful for e-commerce, real-time updates, or multi-tenant apps).cache:store configurations) by allowing nested cache pools (e.g., per-tenant or per-region caches).config/cache.php under stores.predis:
'predis' => [
'driver' => 'predis',
'connection' => 'redis',
'prefix' => 'laravel_predis_',
],
\Predis\Client) configured with Redis connection details (host, port, auth, etc.). Laravel’s existing Redis config (via redis.php) can be reused.php-cache/redis-adapter) offer better performance for our use case?Cache::store()).php-redis>=5.3).predis).ext-redis is optional but recommended for PhpRedis).// config/cache.php
'stores' => [
'predis' => [
'driver' => 'predis',
'client' => function ($app) {
return new \Predis\Client([
'scheme' => 'tcp',
'host' => config('redis.host'),
'port' => config('redis.port'),
'password' => config('redis.password'),
]);
},
'prefix' => 'predis_',
],
],
// app/Providers/AppServiceProvider.php
public function register()
{
Cache::extend('predis', function ($app) {
return new \Cache\PredisCachePool(
new \Predis\Client(config('redis.client'))
);
});
}
// Use as-is: Cache::store('predis')->get('key');
// Or alias in config/cache.php:
'default' => env('CACHE_DRIVER', 'predis'),
predis.metrics)."scripts": {
"test:predis": "php artisan cache:clear && vendor/bin/phpunit --filter PredisTest"
}
php-cache/redis-adapter.Predis\Client::setOption('logging', true);
user:{id}, product:{category}) to avoid "tag explosion."Cache::rememberForever) must be tested.new \Predis\Client(['parameters' => ['connection_pool' => true]])
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Redis Node Failure | Cache unavailability | Use Redis Sentinel or fallback store. |
| Predis Bug | Silent cache corruption | Implement cache validation (e.g., checksums). |
| Network Partition | Timeouts | Configure retry logic in Predis client. |
| PHP-Cache Abandonment | No future updates | Fork or migrate to php-cache/redis-adapter. |
| Serialization Issues | Data corruption | Use JSON/IGBinary for complex objects. |
user:{id}:profile).predis.options for timeouts).How can I help you explore Laravel packages today?