[英]PHP predis connect to Redis Sentinel
I've set up a new PHP predis
connection to a redis
server using the documented code. 我已经使用文档中的代码建立了一个与
redis
服务器的新PHP predis
连接。 I can verify it's connected ok, but I don't know how to simply test if the connection exists. 我可以验证它是否可以正常连接,但是我不知道如何简单地测试连接是否存在。
$options = array(
'scheme' => 'tcp',
'host' => '127.0.0.1',
'port' => $port,
'instance' => 'myinstance',
'timeout' => '0.100' // possibly add this to connections?
);
$sentinels = [
"tcp://{$options['host']}:{$options['port']}?timeout={$options['timeout']}",
];
$connection = new Predis\Client($sentinels, [
'replication' => 'sentinel',
'service' => $options['instance'],
]);
if ($connection->isConnected() === true) {
// undocumented-- I don't think this works?
echo "connected";
} else {
echo "failed"; // this is what gets echoed
}
Is there a method to test if the connection is good short of actually reading / writing to it? 有没有一种方法可以测试该连接是否在实际读取/写入之前是否良好?
isConnected()
doesn't appear to work. isConnected()
似乎不起作用。
As suggested by @drot: 如@drot所建议:
$options = array(
'scheme' => 'tcp',
'host' => '127.0.0.1',
'port' => $port,
'instance' => 'myinstance',
'timeout' => '0.100' // possibly add this to connections?
);
$sentinels = [
"tcp://{$options['host']}:{$options['port']}?timeout={$options['timeout']}",
];
$connection = new Predis\Client($sentinels, [
'replication' => 'sentinel',
'service' => $options['instance'],
]);
// do this:
$connection->connect();
if ($connection->isConnected() === true) {
// undocumented-- I don't think this works?
echo "connected";
} else {
echo "failed"; // this is what gets echoed
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.