swoft-cloud / swoft

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

redis的消息发布与订阅没有反应 #1391

Open webphplove opened 3 years ago

webphplove commented 3 years ago
Q A
Bug report? yes
Feature request? yes
Swoft version 2.0.10
Swoole version 4.5.1
PHP version PHP 7.3.21
Runtime environment Ubuntu

Describe the bug A clear and concise description of what the bug is.

我开启了一个进程处理redis的发布订阅,代码如下:

<?php
namespace App\Process;

use Swoft\Bean\Annotation\Mapping\Bean;
use Swoft\Db\Exception\DbException;
use Swoft\Log\Helper\CLog;
use Swoft\Process\Process;
use Swoft\Process\UserProcess;
use Swoft\Redis\Redis;

/**
 * Class QueueSubscribeProcess
 * @package App\Process
 * @Bean()
 */
class QueueSubscribeProcess extends UserProcess
{

    /**
     * @param Process $process
     *
     * @throws DbException
     */
    public function run(Process $process): void
    {
        while (true) {

            ini_set('default_socket_timeout', -1); //不超时

            // 订阅 2 个频道
            Redis::subscribe(['test'], function ($redis, $pattern, $chan, $msg){
                echo "Pattern: $pattern\n";
                echo "Channel: $chan\n";
                echo "Payload: $msg\n";
            });
            Coroutine::sleep(3);
        }
    }
}

我使用redis发布消息,这个订阅没有反应。 我也通过swoft程序发布消息,而程序的订阅和redis客户端订阅频道,也没有任何反应

sakuraovq commented 3 years ago

cli 测试有反应的 看看 使用是否正确 框架没有做封装 使用的 redis 扩展

webphplove commented 3 years ago

我用swoole 的redis有反应, 而用swoft 一定反应都没有