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; } }