gpt4 book ai didi

PHP 使用网络端口连接到 Redis 服务。 Redis 异常 : No such file or directory

转载 作者:可可西里 更新时间:2023-11-01 11:47:47 25 4
gpt4 key购买 nike

PHP 使用网络端口连接到 Redis 服务。 RedisException:没有这样的文件或目录。我又开了一个redis,但是没有问题。

[root@iZwz96u12ozbs8aqnrwvo9Z Lib]# ps aux | grep redis
root 18378 0.1 0.8 163100 16204 ? Ssl 10:06 0:04 redis-5.0.5/src/redis-server 127.0.0.1:63306
root 22998 0.0 0.2 142952 5320 ? Ssl 11:16 0:00 redis-server 127.0.0.1:6379
root 23130 0.0 0.0 112704 976 pts/0 R+ 11:18 0:00 grep --color=auto redis
[root@iZwz96u12ozbs8aqnrwvo9Z Lib]# redis-cli -p 63306
127.0.0.1:63306> ping
PONG
127.0.0.1:63306> exit
[root@iZwz96u12ozbs8aqnrwvo9Z Lib]# redis-cli -p 6379
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> exit
[root@iZwz96u12ozbs8aqnrwvo9Z Lib]# redis-server --version
Redis server v=3.2.12 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=7897e7d0e13773f
[root@iZwz96u12ozbs8aqnrwvo9Z Lib]# ../../redis/redis-5.0.5/src/redis-server --version
Redis server v=5.0.5 sha=c956f3fe:0 malloc=jemalloc-5.1.0 bits=64 build=d7a4b6366565957e

Redis at 6379 可以用我的代码,另一个不行。

// is bad
try {
$this->redis = new Redis();
$this->redis->connect('127.0.0.1', 63306);
} catch (Exception $e) {
throw new Exception("Redis 连接失败_$e");
}

// is work
try {
$this->redis = new Redis();
$this->redis->connect('127.0.0.1', 6379);
} catch (Exception $e) {
throw new Exception("Redis 连接失败_$e");
}

正确的输出是:

{"code":0,"status":"成功","data":"xxxxxxxxxxxxxxxxxx"}

错误输出为:

PHP Fatal error:  Uncaught Exception: Redis 连接失败_RedisException: No such file or directory in /usr/share/nginx/html/exbook/app/Lib/WeChat.php:23
Stack trace:
#0 /usr/share/nginx/html/exbook/app/Lib/WeChat.php(23): Redis->connect('127.0.0.1', 63306)
#1 /usr/share/nginx/html/exbook/app/Lib/WeChat.php(52): App\Lib\WeChat->__construct()
#2 /usr/share/nginx/html/exbook/app/Lib/WeChat.php(135): App\Lib\WeChat::getWeChat()
#3 {main} in /usr/share/nginx/html/exbook/app/Lib/WeChat.php:25
Stack trace:
#0 /usr/share/nginx/html/exbook/app/Lib/WeChat.php(52): App\Lib\WeChat->__construct()
#1 /usr/share/nginx/html/exbook/app/Lib/WeChat.php(135): App\Lib\WeChat::getWeChat()
#2 {main}
thrown in /usr/share/nginx/html/exbook/app/Lib/WeChat.php on line 25

最佳答案

我通过更改端口号解决了这个问题。

在我的centos上,redis端口小于20000,可以用php。它会在20000-30000端口号报错。但是任何可以使用的端口,例如 63306,都可以在我的 manjaro 上使用 php。

关于PHP 使用网络端口连接到 Redis 服务。 Redis 异常 : No such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56880296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com