phpfuelphp

How to check whether the Redis server is running


How to check whether the Redis server is running?

If it's not running, I want to fallback to using the database.

I'm using the FuelPHP framework, so I'm open to a solution based on this, or just standard PHP.


Solution

  • What you can do is try to get an instance (\Redis::instance()) and work with it like this:

    try
    {
        $redis = \Redis::instance();
        // Do something with Redis.
    }
    catch(\RedisException $e)
    {
        // Fall back to other db usage.
    }
    

    But preferably you'd know whether redis is running or not. This is just the way to detect it on the fly.