Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davidepedone/laravel-redis-fallback
Redis cache fallback for Laravel 4
https://github.com/davidepedone/laravel-redis-fallback
Last synced: about 1 month ago
JSON representation
Redis cache fallback for Laravel 4
- Host: GitHub
- URL: https://github.com/davidepedone/laravel-redis-fallback
- Owner: davidepedone
- Created: 2015-03-23T11:50:22.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-03-24T08:02:22.000Z (over 9 years ago)
- Last Synced: 2024-09-27T22:20:54.682Z (about 2 months ago)
- Language: PHP
- Homepage: https://packagist.org/packages/davidepedone/laravel-redis-fallback
- Size: 148 KB
- Stars: 4
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Redis cache fallback for Laravel4
If you use Redis as cache driver on Laravel 4 and for some reason Redis server became unavailable, you will end up with a Connection Refused exception.
This package simply checks for the connection and if test fails, cache is switched to file driver.
As soon as Redis come back it will be used again.##How it works
```LaravelRedisFallbackServiceProvider``` class extends ```Illuminate\Cache\CacheServiceProvider``` and overrides ```register()``` method as follow:
```php
public function register(){$this->app->bindShared('cache', function($app){
return new \Davidepedone\LaravelRedisFallback\LaravelRedisFallback($app);
});
...
}
```
```LaravelRedisFallback``` class extends ```Illuminate\Cache\CacheManager``` and overrides ```createRedisDriver()``` method as follow:
```phpprotected function createRedisDriver() {
$redis = $this->app['redis'];
$redisStore = new RedisStore($redis, $this->getPrefix());try{
$redisStore->getRedis()->ping();
return $this->repository( $redisStore );}catch(\Exception $e){
return parent::createFileDriver();
}
}```
##How to use
Install LaravelRedisFallback as a Composer package, adding this line to your composer.json:```php
"davidepedone/laravel-redis-fallback": "dev-master"
```
and update your vendor folder running the ```composer update ``` command.Replace the default cache service provider:
```php
'providers' => array(
...
//'Illuminate\Cache\CacheServiceProvider',
...
'Davidepedone\LaravelRedisFallback\LaravelRedisFallbackServiceProvider'
...
)
```Enjoy!