Hi walkor
我在webman框架中使用redis-queue,在消费类的业务代码中使用的ThinkORM操作数据库,出现DB实例失效的情况,但http服务进程中可以正常操作数据库。看现象像是redis队列闲置后,导致Db连接在Pool中被关闭后(如超时),Context中仍持有旧对象。我在网上查到的解决方法是 \Webman\Context::destroy(); 但觉得这样做不太靠谱;请问有更好的方法吗?
public function consume($data){
///省略其它不相关的代码,
DeviceModel::where(DeviceModel::DEVICE_NO, $deviceNo)->find();
}
"class":"app\queue\redis\DeviceEventLogQueue","function":"consume","context":{"device_no":"6398213514332561","event_type":8,"event_msg":"成功","event_time":1770185504872},"code":0,"message":"Call to a member function trigger() on null","file":"/vendor/topthink/think-orm/src/db/PDOConnection.php","line":941,"trace":"/vendor/topthink/think-orm/src/db/BaseQuery.php(1559): think\db\PDOConnection->find()

"php": ">=8.1",
"workerman/webman-framework": "^2.1",
发下 webman/redis-queue 版本,
composer info | grep redis-queuewebman/redis-queue v2.1.0 Redis message queue plugin for webman.
workerman/redis-queue v1.2.1 Message queue system written in PHP based on workerman and backed by Re.
webman/redis-queue版本不是最新的,更新到
composer require webman/redis-queue ^2.1.1好的,谢谢walkor,更新到^2.1.1后这个问题就解决了是吧?
webman/redis-queue ^2.1.1 的核心价值是稳,主要关键点如下:
修复了重试逻辑、Redis 重连的核心 BUG,避免任务丢失和进程异常;
解决了内存泄漏隐患,适配高版本 Redis,提升长期运行稳定性;
无破坏性变更,可直接升级,无需修改原有业务代码。
这个版本,没有看到Db重连的修复
它做了每次执行完业务销毁Context上下文,避免上下文里缓存了关闭连接的数据库实例
嗯嗯好的