How to check whether the Redis server is running

给你一囗甜甜゛ 提交于 2019-12-03 09:44:43
Frank de Jonge

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.

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.

you can do it by this way.

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

echo $redis->ping();

and then check if it print +PONG, which show redis-server is running.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!