swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 786 forks source link

为什么在Listener下调用redis会报错 #1287

Open qiuzq321 opened 4 years ago

qiuzq321 commented 4 years ago

swoft版本2.0.1

Describe the bug PHP Fatal error: Swoole\Coroutine\Channel::push(): must be called in the coroutine. in /home/swoft-study/integrating/vendor/swoft/connection-pool/src/AbstractPool.php on line 271



namespace App\Listener;

use Exception;
use Swoft\Event\Annotation\Mapping\Listener;
use Swoft\Event\EventHandlerInterface;
use Swoft\Event\EventInterface;
use Swoft\Server\ServerEvent;

/**
 * Class RegisterServer
 * @package App\Listener
 * @Listener(ServerEvent::BEFORE_START)
 */
class RegisterServer implements EventHandlerInterface
{
    public function handle(EventInterface $event): void
    {
            $redisCon = bean('redis.pool')->getConnection();
            $redisCon->setRelease(true);    //设置连接可以重用
            echo ($redisCon->hset("integrating_message_job", 'haha', 0));
            echo 'dfsdfs';
        $redisCon->release($redisCon);
            exit
}
inhere commented 4 years ago

升级到最新版本看看呢