在我的 Laravel 应用程序中测试 Redis 发布/订阅。执行这个 artisan 命令
public function callback(){
print_r(func_get_args());
}
public function handle(): int
{
$client = Redis::connection()->client();
if($client->isConnected()){
$this->line('Connected'); // Prints "Connected"
}
$client->subscribe(['exchanges'], [$this, 'callback']);
$client->publish('exchanges', json_encode($this->getExchanges()));
return 0;
}
给出了这个错误:
read error on connection to 127.0.0.1:6379
at app/Console/Commands/Client/Start.php:49
45▕ if($client->isConnected()){
46▕ $this->line('Connected');
47▕ }
48▕
➜ 49▕ $client->subscribe(['exchanges'], [$this, 'callback']);
50▕ $client->publish('exchanges', json_encode($this->getExchanges()));
51▕
52▕ return 0;
53▕
1 app/Console/Commands/Client/Start.php:49
Redis::subscribe()
subscribe() 方法有什么问题?
最佳答案
ini_set('default_socket_timeout', -1) 对我有用。
关于redis - Laravel Redis 连接到 127.0.0.1 时读取错误 :6379,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69595148/