From b03de378b0595325c3d7621b20171a0ed28f56a1 Mon Sep 17 00:00:00 2001 From: lkddi Date: Tue, 3 Mar 2026 14:57:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=85=B7=EF=BC=9A=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20room:clear-online-cache=20=E5=91=BD=E4=BB=A4=EF=BC=8C?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E6=B8=85=E7=90=86=E6=88=BF=E9=97=B4=E5=B9=BD?= =?UTF-8?q?=E7=81=B5=E5=9C=A8=E7=BA=BF=E8=84=8F=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/ClearRoomOnlineCache.php | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 app/Console/Commands/ClearRoomOnlineCache.php diff --git a/app/Console/Commands/ClearRoomOnlineCache.php b/app/Console/Commands/ClearRoomOnlineCache.php new file mode 100644 index 0000000..bbf385d --- /dev/null +++ b/app/Console/Commands/ClearRoomOnlineCache.php @@ -0,0 +1,65 @@ +info("Redis 前缀:\"{$prefix}\""); + $this->info('开始扫描 room:*:users ...'); + + do { + [$cursor, $keys] = Redis::scan($cursor, ['match' => $prefix.'room:*:users', 'count' => 100]); + foreach ($keys ?? [] as $fullKey) { + // 去掉 Redis 前缀,还原为 Laravel Facade 使用的短 Key + $shortKey = $prefix ? substr($fullKey, strlen($prefix)) : $fullKey; + Redis::del($shortKey); + $this->line(" ✓ 已清除:{$shortKey}"); + $cleaned++; + } + } while ($cursor !== '0'); + + $this->info("完成!共清理 {$cleaned} 个房间的在线名单。"); + $this->info('用户下次进房会重新写入正确数据,人数从 0 开始准确累计。'); + + return self::SUCCESS; + } +}