How to check whether the Redis server is running
All answers are great,
aAnother way can be to check if default REDIS port is listening
i.e port number 6379
lsof -i:6379
if you don't get any output for above command then it implies redis is not running.
redis-cli -h host_url -p 6379 ping
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.
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.