redis服务正常,通过非命令行工具执行队列可正常消费
protected function execute(InputInterface $input, OutputInterface $output){
$queue = 'send-email';
$data = ['to' => 'joe@gmail.com', 'content' => 'hello'];
Client::send($queue, $data);
return self::SUCCESS;
}
Fatal error: Uncaught Error: Call to a member function add() on null in D:\Develop\gitJect\admin-api\vendor\workerman\workerman\Connection\AsyncTcpConnection.php:215
Stack trace:
#0 D:\Develop\gitJect\admin-api\vendor\workerman\redis\src\Client.php(450): Workerman\Connection\AsyncTcpConnection->connect()
#1 D:\Develop\gitJect\admin-api\vendor\workerman\redis\src\Client.php(274): Workerman\Redis\Client->connect()
#2 D:\Develop\gitJect\admin-api\vendor\workerman\redis-queue\src\Client.php(76): Workerman\Redis\Client->__construct('redis://127.0.0...', Array)
#3 D:\Develop\gitJect\admin-api\vendor\webman\redis-queue\src\Client.php(45): Workerman\RedisQueue\Client->__construct('redis://127.0.0...', Array)
#4 D:\Develop\gitJect\admin-api\vendor\webman\redis-queue\src\Client.php(58): Webman\RedisQueue\Client::connection('default')
#5 D:\Develop\gitJect\admin-api\app\command\OceanAgent.php(50): Webman\RedisQueue\Client::__callStatic('send', Array)
#6 D:\Develop\gitJect\admin-api\vendor\symfony\console\Command\Command.php(298): ap in D:\Develop\gitJect\admin-api\vendor\workerman\workerman\Connection\AsyncTcpConnection.php on line 215
开发环境
window11
php7.4.3
webman 1.5.0
redis-queue 1.2
Webman\RedisQueue\Client 是异步的,所有异步的组件都需要在workerman的运行环境使用,运行脚本命令不是workerman的运行环境,所以用不了。
用 Webman\RedisQueue\Redis ,它是同步的,可以在脚本里用。
好的,使用同步可以正常运行