Update: 2026-07-04 18:43:56

This commit is contained in:
Hamza-Ayed
2026-07-04 18:43:57 +03:00
parent 3412f1b753
commit 3e0b4cbf64
65 changed files with 2260 additions and 118 deletions
+56 -1
View File
@@ -230,6 +230,10 @@ $io->on('workerStart', function () use ($io, $INTERNAL_KEY) {
if (isset($ops['hmset'])) {
$pipe->hmset($profileKey, $ops['hmset']);
// 🆕 Cache public driver data للقراءة السريعة من get.php (24h TTL)
$publicKey = "driver:public:$driverId";
$pipe->hmset($publicKey, $ops['hmset']);
$pipe->expire($publicKey, 86400);
}
if (isset($ops['expire'])) {
$pipe->expire($profileKey, $ops['expire']);
@@ -418,6 +422,34 @@ $io->on('workerStart', function () use ($io, $INTERNAL_KEY) {
logMsg("✅ Ride #$rideId taken by #$winnerDriverId.");
$connection->send('OK');
// ── 7. Update Ride State (Redis Cache فقط — بدون Forward)
} elseif ($action === 'update_ride_state') {
$rideId = $post['ride_id'] ?? null;
$status = $post['status'] ?? '';
$driverId = $post['driver_id'] ?? '';
$passengerId = $post['passenger_id'] ?? '';
if (!$rideId || !$status) {
$connection->send('Error: Missing ride_id or status');
return;
}
if ($redis) {
$stateKey = "ride:$rideId:state";
$stateData = [
'status' => $status,
'driver_id' => $driverId,
'passenger_id' => $passengerId,
'updated_at' => time(),
];
$redis->hmset($stateKey, $stateData);
$redis->expire($stateKey, 86400);
logMsg("🚗 Ride #$rideId → status: $status (cached in Redis)");
}
$connection->send('OK');
// ── 5. Force Disconnect ───────────────────────────────
} elseif ($action === 'force_disconnect') {
$driverId = $post['driver_id'] ?? null;
@@ -467,6 +499,20 @@ $io->on('workerStart', function () use ($io, $INTERNAL_KEY) {
}
$connection->send('OK');
// ── 7. Cache Driver Public Data ─────────────────────────
} elseif ($action === 'cache_driver_public') {
$driverId = $post['driver_id'] ?? null;
$data = json_decode($post['data'] ?? '[]', true);
if ($driverId && $redis && !empty($data)) {
$key = "driver:public:$driverId";
$redis->hmset($key, $data);
$redis->expire($key, 86400);
$connection->send('OK');
} else {
$connection->send('Error');
}
} else {
$connection->send('Unknown action');
}
@@ -631,7 +677,9 @@ $io->on('connection', function ($socket) use ($INTERNAL_KEY) {
if ($needHmset) {
$eventBuffer[$driverId]['hmset'] = [
'id' => $driverId, 'heading' => $heading, 'speed' => $speed, 'status' => $status, 'updated_at' => $now
'id' => $driverId, 'lat' => $lat, 'lng' => $lng,
'heading' => $heading, 'speed' => $speed,
'status' => $status, 'updated_at' => $now
];
$state['speed'] = $speedMs;
$state['heading'] = $heading;
@@ -667,6 +715,13 @@ $io->on('connection', function ($socket) use ($INTERNAL_KEY) {
if ($needGeoadd) {
$state['lat'] = $lat;
$state['lng'] = $lng;
// 🆕 تحديث الموقع في driver:public (حتى لو ما تغير speed/heading)
if (!isset($eventBuffer[$driverId]['hmset'])) {
$eventBuffer[$driverId]['hmset'] = [
'id' => $driverId, 'lat' => $lat, 'lng' => $lng,
'updated_at' => $now
];
}
}
}
});