cli 模式报错
[2019-11-20T14:33:25+08:00][ error ] [8]PDO::prepare(): send of 68 bytes failed with errno=32 Broken pipe error
相关代码
class RedisSubscribe { public function subscribe() { $redis = BaseRedis::plocal(); $redis->setOption(\Redis::OPT_READ_TIMEOUT, -1); $redis->psubscribe(array(‘[email protected]__:expired‘), function ($redis, $pattern, $chan, $msg) { Log::info(‘[订阅事件] 过期KEY ‘ . $msg); $flag = strstr($msg,":"); if(empty($flag)){ Log::error(‘[订阅事件] 非法的消息类型 ‘.$msg); return false; } $originData = explode(‘:‘,$msg); $event_key = $originData[1]??‘0‘; $event_status = $originData[0]??‘0‘; if($event_status == RedisTaskQueue::ORDER_TIMEOUT_EVENT){ Log::info(‘[订阅事件] 订单超时事件 ‘.$event_key); $order = PayOrderModel::get([‘order_no‘ => $event_key]); Log::info(‘[订阅事件] 订单 ‘.$event_key); if ($order[‘status‘] == 0) { $updateData = [ ‘id‘ => $order[‘id‘], ‘status‘ => 2, ‘notify_status‘ => 0, ‘pay_time‘ => time(), ‘remark‘ => ‘超时队列事件‘ ]; $res = PayOrderModel::update($updateData); Log::info(‘[订阅事件] 更新订单 ‘ . json_encode($res)); } } }); } }
问题就出现在以上代码中查询和更新数据库问题
$order = PayOrderModel::get([‘order_no‘ => $event_key]);
本以为开启需要断线重连,就没问题了,结果隔一段时间有出现了同样的错误
// 是否需要断线重连 ‘break_reconnect‘ => false,
问题分析,这里采用的Redis的订阅模式,持久性的
解决办法,通过任务队列解决
$isPushed = redis_queue(RedisTaskQueue::QUEUE_EVENT, $data);
把redis订阅服务获取到的信息,发布think-queue队列中,在队列中在进行处理数据库相关操作
原文地址:https://www.cnblogs.com/tinywan/p/11898671.html
时间: 2024-10-07 13:15:30