'match', "msg" => "匹配成功", "info" => ['room_id'=>$room['room_id'],"players"=>$players], ]; //清理房间数据 Redis::set($room['room_id'] . '_info',''); Redis::set($room['room_id'] . '_questions',''); Gateway::sendToGroup($room['room_id'], json_encode($message)); echo "匹配成功: {$data['client_id']} 、 {$room['client_id']}\n"; }else{ //新建一个房间 $room_id = $this->get_room_id(); $room = ['room_id'=>$room_id, "user_id"=>$data['user_id'], "avatar"=>$data['avatar'], "username"=>$data['username'],'client_id'=>$data['client_id']]; Redis::set($data['level'], json_encode($room)); } } } public function get_room_id() { while (1) { $room_id = 'room_' . rand(10000,99999); $count = Gateway::getUidCountByGroup($room_id); if(!$count){ return $room_id; } } } }