busy进程 log出現redis錯誤

aidec

您好,我的workerman运行定时发送email的任务
每隔一段时间就会出现busy的状况(大概运行20天就会出现)
restart后又能在使用20天
我看workerman.log会出现这样的错误

2021-09-23 08:07:07 pid:13187 Worker[13187] process terminated with ERROR: E_ERROR "Uncaught RedisException: read error on connection to localhost:6379 in /var/xxxxxx/autoWriteLog.php
Stack trace:
#0 /var/xxxxxx/autoWriteLog.php(280): Redis->lLen('OrderSe...')

使用的是 use Workerman\Redis\Client;
這是redis连线超时的缘故吗?

1647 2 0
2个回答

xiuwang

Uncaught RedisException: read error on connection to 这个是redis扩展的报错。

autoWriteLog.php 里的redis实例在onWorkerStart里初始化,不要提前初始化

  • aidec 2021-09-23

    我的确是提前初始化,我有开好几个worker
    使用global $redis的方式
    那我再改成个别在每个worker的onWorkerStart new Redis
    谢谢您的帮助

  • aidec 2021-09-23

    在请问一下,我的onWorkerStart 里面有一个timer
    new redis 要写在 timer里面还是外面

  • xiuwang 2021-09-24

    一般来说都可以。

  • aidec 2021-09-24

    感谢您

小阳光

1 redis链接在每个进程启动后链接

2 出现redis扩展抛出来的异常,丢弃此链接,重试获取链接

public static function __callStatic($name, $arguments)
{
try {
return static::$_manager->connection()->{$name}(... $arguments);
} catch (\RedisException $ex) {
Log::info('redis 断线重连');
try {
static::$_manager->connection()->disconnect();
} catch (\Exception $exception) {
}
self::start(null);//这里在链接redis
return static::$_manager->connection()->{$name}(... $arguments);
}
}

  • 暂无评论
年代过于久远,无法发表回答
🔝