Default to Laravel File cache if redis is down
One way to solve this problem is to overwrite Laravel's default Illuminate\Cache\CacheManager
class and alter the ioc binding
class MyCacheManager extends Illuminate\Cache\CacheManager
{
protected function createRedisDriver(array $config)
{
try {
return parent::createRedisDriver($config);
} catch (\Exception $e) {
//Error with redis
//Maybe there is a more explicit exception ;)
return $this->resolve('file');
}
}
}
In some ServiceProvider
$this->app->singleton('cache', function($app)
{
return new MyCacheManager($app);
});
This solution will also keep the Cache
facade working :)