在我的Laravel应用程序中测试Redis pub/sub。执行这个工匠命令
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()
订阅()方法有什么问题?
ini_set('default_socket_timeout', -1) for me.