自定义进程监听redis 重启报错

zhaogh

问题描述

新增了个process用来监听redis过期的key,但是发现重启stop的时候报了错误
Workerman[start.php] stopping ...
worker[redis.notify_ex:15627] exit with status 9
Workerman[start.php] has been stopped
Workerman[start.php] start in DEBUG mode

想请教一下如何解决这个status 9的异常退出问题呢?

程序代码

<?php
namespace process;

use app\constants\TalkEventConstant;
use app\service\message\MessageSubscribeHandleService;
use support\Message;
use support\Redis;

class RedisNotifyEx
{
    public function onWorkerStart()
    {
        Redis::setOption(\Redis::OPT_READ_TIMEOUT, -1);
        Redis::setOption(\Redis::OPT_PREFIX, '');

        $redisPrefix = env('REDIS_PREFIX', '');

        Redis::pSubscribe(['__keyevent@0__:expired'], function ($key, $event) use ($redisPrefix) {
            if (!preg_match('/^' . $redisPrefix . '/', $key)) {
                return;
            }

            echo 'RedisNotifyEx:' . __LINE__ . PHP_EOL;
            echo 'key:' . $key . PHP_EOL;
            echo 'event:' . $event . PHP_EOL;

            if (preg_match("/^{$redisPrefix}rds-string:at-tip/", $key)) { // AT提醒过期
                $arr = explode(':', $key);

                [$groupId, $userId] = explode('_', $arr[3]);

                MessageSubscribeHandleService::instance()->handle(
                    Message::create(TalkEventConstant::GROUP_AT_TIP_REMOVE, [
                        'group_id' => $groupId,
                        'user_id' => $userId,
                    ])
                );

                echo 'is_at!!!!' . PHP_EOL;
            }
        });
    }
}

报错信息

Workerman[start.php] stopping ...
worker[redis.notify_ex:15627] exit with status 9
Workerman[start.php] has been stopped
Workerman[start.php] start in DEBUG mode
-------------------------------------------------------- WORKERMAN --------------------------------------------------------
Workerman version:4.1.13          PHP version:8.1.21           Event-Loop:\Workerman\Events\Event
--------------------------------------------------------- WORKERS ---------------------------------------------------------
proto   user            worker                                   listen                      processes    status           
tcp     www             webman                                   http://0.0.0.0:8787         16            [OK]            
tcp     www             monitor                                  none                        1             [OK]            
tcp     www             redis.notify_ex                          none                        1             [OK]            
tcp     www             plugin.tinywan.rpc.text.protocol         text://0.0.0.0:9512         4             [OK]            
tcp     www             plugin.webman.stomp.consumer             none                        1             [OK]            
tcp     www             plugin.webman.gateway-worker.gateway     websocket://0.0.0.0:7272    4             [OK]            
tcp     www             plugin.webman.gateway-worker.worker      none                        8             [OK]            
tcp     www             plugin.webman.gateway-worker.register    text://127.0.0.1:1236       1             [OK]            
tcp     www             plugin.webman.redis-queue.consumer       none                        8             [OK]            
---------------------------------------------------------------------------------------------------------------------------
270 1 0
1个回答

latin

进程一直在运行 pSubscribe 上,无法退出,被主进程强行退出了,正常现象,不用管。
如果在意就用 workerman/redis 去pSubscribe

  • zhaogh 2024-05-17

    谢谢大佬,已改为workerman/redis

×
🔝