我完全不知道发生了什么。我正在尝试连接到redis服务器,我可以使用redis cli很好地连接,但是使用predis我得到了第一个错误。如果我使用redis cli,一切都很好。我100%确信密码和IP是正确的。服务器上的防火墙已关闭。
Fatal error: Uncaught Predis\Connection\ConnectionException: Connection timed out [tcp://[server ip]:6379] in /path/to/.../vendor/predis/predis/src/Connection/AbstractConnection.php:155
Stack trace:
# 0 path/to/.../vendor/predis/predis/src/Connection/StreamConnection.php(128): Predis\Connection\AbstractConnection->onConnectionError('Connection time...', 110)
# 1 path/to/.../vendor/predis/predis/src/Connection/StreamConnection.php(178): Predis\Connection\StreamConnection->createStreamSocket(Object(Predis\Connection\Parameters), 'tcp://[server ip]...', 4)
# 2 path/to/.../vendor/predis/predis/src/Connection/StreamConnection.php(100): Predis\Connection\StreamConnection->tcpStreamInitializer(Object(Predis\Connection\Parameters))
# 3 path/to/.../vendor/predis/predis/src/Connection/AbstractConnection.php(81): Predis\Connection\StreamConnection->createResource()
# 4 path/to/.../vendor/predis/predis/src/Connection/AbstractConnection.php on line 155
这是redis cli的响应:
$ redis-cli -h [server ip]
[server ip]:6379> AUTH [redis password]
OK
[server ip]:6379> PING
PONG
[server ip]:6379>
代码如下:
<?php
include '../../vendor/autoload.php';
function sendMessage($tube, $msg) {
$client = new Predis\Client(array(
"scheme" => "tcp",
//"host" => "127.0.0.1",
"host" => "[server ip]",
"port" => 6379
), array(
"parameters" => [
"password" => "[redis password]"
]
));
$client->rpush($tube, $msg);
}
sendMessage('test', "test");
?>
任何帮助都将不胜感激!
暂无答案!
目前还没有任何答案,快来回答吧!