1、合作商余额查询
2、分油账户司机可用额度
This commit is contained in:
@@ -29,6 +29,31 @@ class QueueService
|
||||
return $message ? json_decode($message, true) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 阻塞式取出消息:队列空时挂在 Redis 上等,有消息立刻返回。
|
||||
*
|
||||
* 相比 pop() + sleep(1) 的轮询,取到消息的延迟从「最多 1 秒」降到接近 0,
|
||||
* 对「下单 -> 调上游发放」这种链路首段能实打实省掉一截等待。
|
||||
*
|
||||
* @param string $queueName
|
||||
* @param int $timeout 最长阻塞秒数(到点返回 null,便于外层做兜底巡检)
|
||||
* @return array|string|null
|
||||
*/
|
||||
public function bpop($queueName, $timeout = 5)
|
||||
{
|
||||
// BLPOP 会把连接挂住 $timeout 秒,必须短于 Redis 连接的读超时
|
||||
// (未显式配置时取 PHP default_socket_timeout,通常 60 秒),
|
||||
// 否则会抛读超时异常而不是正常返回 null。这里夹到 30 秒以内。
|
||||
$timeout = max(1, min(30, (int) $timeout));
|
||||
// Predis 的 blpop 返回 [队列名, 消息],超时返回 null
|
||||
$res = $this->redis->blpop([$queueName], $timeout);
|
||||
if (empty($res[1])) {
|
||||
return null;
|
||||
}
|
||||
$decoded = json_decode($res[1], true);
|
||||
return $decoded === null ? $res[1] : $decoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* 延迟推送(ZSET)
|
||||
* @param string $queueName
|
||||
|
||||
Reference in New Issue
Block a user