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.
To start Redis client, open the terminal and type the command redis-cli. This will connect to your local server and now you can run any command. In the above example, we connect to Redis server running on the local machine and execute a command PING, that checks whether the server is running or not.
If you want to test redis connection once at startup, use the ping() command. The command ping() checks the connection and if invalid will raise an exception. Note - the connection may still fail after you perform the test so this is not going to cover up later timeout exceptions.
In order to check if Redis is really working. Monitor REDIS realtime. The reload your application and see if something is going in your monitor. You should be able to see some SET happening.
You can use command line to determine if redis is running:
redis-cli ping
you should get back
PONG
that indicates redis is up and running.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With