Jan*_* P. 12
解决此问题的一种方法是覆盖Laravel的默认Illuminate\Cache\CacheManager
类并更改ioc绑定
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');
}
}
}
Run Code Online (Sandbox Code Playgroud)
在某些ServiceProvider中
$this->app->singleton('cache', function($app)
{
return new MyCacheManager($app);
});
Run Code Online (Sandbox Code Playgroud)
这个解决方案也将保持Cache
外观工作:)