How to check if a Redis server is running

How to check if a Redis server is running?

If it is not running, I want to stop using the database.

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

+14
source share
3 answers

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 it is advisable that you know if Redis is working or not. This is just a way to discover it on the fly.

+4
source

You can use the command line to determine if redis is working:

 redis-cli ping 

you must return

 PONG 

which indicates that redis is up and running.

+28
source

you can do it this way.

 $redis = new Redis(); $redis->connect('127.0.0.1', 6379); echo $redis->ping(); 

and then check if it is printed +PONG on which the redis server is running.

0
source

Source: https://habr.com/ru/post/1403394/


All Articles