What do you do when the redis connection is down? I've been pulling my hair out on this. Everything works great when redis is up and running. So I wanted to test and build a solid fall back to the DB when redis was down. The problem became apparent when I realized that the init() of CRedisCache does not create a connection or ping for the sign of a connection. But once I execute a command against the cache, if the connection is down Predis will throw the exception Predis_CommunicationException.

I never thought this would be an issue. Anytime I called a Yii::app()->cache-> command I wrapped it in try/catch blocks and caught Predis_CommunicationException. My problem is that even if I catch the error, it still exists in the Yii exception head space and I kills the stack at a later point.

When I put the following in my config/main.php, it eliminates the display of any error data which was an earlier problem. Unfortunately, the exception is still sitting in the errorHandler on CApplication(i think that's the obj location). And because of that, CApplication->handleError is still called down the stack and it exits the app instead of skipping over the exception.

When I attempt to get a key from redis, I call this. Be reminded, when redis is up this works like a charm. It's only the persistence of the catch (when redis is down) in Yii's errorHandler that is the problem site wide.

I kept getting a standard Yii uncaught exception that gave the error name and message which killed the app.

FYI: I use PHPStorm with xdebug. I ran through the stack on this one line by line, and stepped into every call. I couldn't figure out why the Predis exception was still being called after I caught it. Looks like even setting an event->exception to "handled" still gets a exit(1). Curious why.

I'm starting to think this has something to do with how Yii manages "uncaught" exceptions in the handleError() in CApplication. Not sure what to make of this since I have caught the error everytime I call Yii::app()->cache, and by using CApplication->onException in config/main.php, set $event->handled.