Redis error
read error on connection to 172.128.6.18:6380
问题描述:
环境:PHP
当长时间连接redis(在队列消费进程中连接redis),而没有释放,服务端的对客户端的连接会断开,但是客户端因缓存的连接,一直处于连接状态,导致执行redis操作时报连接错误。
解决办法:
每次使用前,调用 reconnect()方法。该方法会通过ping的方式检测当前连接是否存在,如果不存在重新连接,如果存在不会重新连接
public function getRedis()
{
if (!$this->_redisModel) {
$this->_redisModel = new Redis();
} else {
$this->_redisModel->reconnect();
}
return $this->_redisModel;
}