redis = $redis_prov->getRedisClient(); $this->loc_key = $loc_key; $this->status_key = $status_key; $this->em = $em; } public function addActiveRider($id, $lat, $lng) { $this->redis->geoadd( $this->loc_key, $lng, $lat, $id ); } public function getAllActiveRiders() { $all_riders = $this->redis->georadius( $this->loc_key, 0, 0, 41000, 'km', ['WITHCOORD' => true] ); $locs = []; foreach ($all_riders as $data) { $id = $data[0]; $lng = $data[1][0]; $lat = $data[1][1]; // get rider details so we can check for availability $rider = $this->getRiderDetails($id); if ($rider != null) { $locs[$id] = [ 'longitude' => $lng, 'latitude' => $lat, ]; } } // error_log(print_r($all_riders, true)); return $locs; } public function removeActiveRider($id) { $this->redis->zrem( $this->loc_key, $id ); } public function incJobOrderCount($id, $status) { $this->redis->hincrby($this->status_key, $id, 1); } public function decJobOrderCount($id, $status) { $this->redis->hincrby($this->status_key, $id, -1); } protected function getRiderDetails($id) { $rider = $this->em->getRepository(Rider::class)->find($id); if ($rider == null) return null; // return only if available if ($rider->isAvailable()) return $rider; return null; } }