Code Monkey home page Code Monkey logo

laravel-redis-fallback's Introduction

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:

	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:

    protected 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:

"davidepedone/laravel-redis-fallback": "dev-master"

and update your vendor folder running the composer update command.

Replace the default cache service provider:

'providers' => array(
	...
	//'Illuminate\Cache\CacheServiceProvider',
	...
	'Davidepedone\LaravelRedisFallback\LaravelRedisFallbackServiceProvider'
	...
)

Enjoy!

laravel-redis-fallback's People

Contributors

davidepedone avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

spartnernl

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.