From 1b694ed6175145961d4e27b2fbc2fea566e08511 Mon Sep 17 00:00:00 2001 From: lamson <171004297@qq.com> Date: Sat, 3 Feb 2024 21:11:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AF=BB=E5=86=99=E5=88=86=E7=A6=BB=20?= =?UTF-8?q?clusterNumber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Consumer/BaseTrait.php | 9 ++++++--- src/function.php | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Consumer/BaseTrait.php b/src/Consumer/BaseTrait.php index 8d32137..772c655 100644 --- a/src/Consumer/BaseTrait.php +++ b/src/Consumer/BaseTrait.php @@ -46,12 +46,15 @@ abstract protected function consume($data = [], Redis $redis = null); public function getListenQueues() { // 在集群模式中,将队列数据均匀分布在不同分片的槽位中 + // 读一定要比写大!!!不然redis会爆!!! $clusterNumber = config('QUEUE.clusterNumber'); + $clusterNumberWrite = config('QUEUE.clusterNumberWrite'); $queue = $this->args['queue']; - + // 读一定要比写大!!!不然redis会爆!!! + $cn = max($clusterNumber ?: 0, $clusterNumberWrite ?: 0); $list[] = $queue; - if ($clusterNumber > 0) { - for ($i = 0; $i <= $clusterNumber; ++$i) { + if ($cn > 0) { + for ($i = 0; $i <= $cn; ++$i) { $list[] = "$queue.$i"; } } diff --git a/src/function.php b/src/function.php index e534e0d..c81209b 100644 --- a/src/function.php +++ b/src/function.php @@ -994,9 +994,12 @@ function redis_list_push(Redis $redis, string $key, $data, bool $left = false) $data = json_encode($data); } $clusterNumber = config('QUEUE.clusterNumber'); - if ($clusterNumber > 0) { + $clusterNumberWrite = config('QUEUE.clusterNumberWrite'); + // 写一定要比读小!!!不然redis会爆!!! + $cn = min($clusterNumber ?: 0, $clusterNumberWrite ?: 0); + if ($cn > 0) { mt_rand(); - $index = mt_rand(-1, $clusterNumber); + $index = mt_rand(-1, $cn); $index > 0 && $key .= ".$index"; }