Update redis cache for rider session when rider registers or logs in. #270

This commit is contained in:
Korina Cordero 2019-10-30 01:50:06 +00:00
parent c3195418b1
commit f70155a137

View file

@ -27,6 +27,7 @@ use App\Ramcar\JOEventType;
use App\Service\InvoiceGeneratorInterface;
use App\Service\MQTTClient;
use App\Service\RedisClientProvider;
use App\Entity\RiderSession;
use App\Entity\Customer;
@ -136,7 +137,7 @@ class RAPIController extends Controller
return $res;
}
public function register(Request $req)
public function register(Request $req, RedisClientProvider $redis)
{
$res = new APIResult();
@ -179,6 +180,12 @@ class RAPIController extends Controller
// save
$em->persist($sess);
$em->flush();
// create redis entry for the session
$redis_client = $redis->getRedisClient();
$redis_key = 'rider.id.' . $sess->getID();
error_log('redis_key: ' . $redis_key);
$redis_client->set($redis_key, '');
}
catch (DBALException $e)
{
@ -202,7 +209,7 @@ class RAPIController extends Controller
return $res->getReturnResponse();
}
public function login(Request $req, EncoderFactoryInterface $ef)
public function login(Request $req, EncoderFactoryInterface $ef, RedisClientProvider $redis)
{
$required_params = [
'user',
@ -248,6 +255,13 @@ class RAPIController extends Controller
$em->flush();
// update redis rider.id.<session id> with the rider id
$redis_client = $redis->getRedisClient();
$redis_key = 'rider.id.' . $this->session->getID();
$rider_id = $rider->getID();
$redis_client->set($redis_key, $rider_id);
$hub = $rider->getHub();
if ($hub == null)
$hub_data = null;