Add command to seed current rider sessions to redis cache. #270
This commit is contained in:
parent
29cc7374cc
commit
c3195418b1
1 changed files with 62 additions and 0 deletions
62
src/Command/SeedRiderSessionsCommand.php
Normal file
62
src/Command/SeedRiderSessionsCommand.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
|
||||
use App\Service\RedisClientProvider;
|
||||
|
||||
use App\Entity\RiderSession;
|
||||
|
||||
class SeedRiderSessionsCommand extends Command
|
||||
{
|
||||
protected $em;
|
||||
protected $redis;
|
||||
|
||||
public function __construct(ObjectManager $om, RedisClientProvider $redis)
|
||||
{
|
||||
$this->em = $om;
|
||||
$this->redis = $redis->getRedisClient();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('rider:session:seed')
|
||||
->setDescription('Seed current rider sessions')
|
||||
->setHelp('Seed current rider sessions');
|
||||
}
|
||||
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
// get all rider sessions
|
||||
$r_sessions = $this->em->getRepository(RiderSession::class)->findAll();
|
||||
foreach ($r_sessions as $session)
|
||||
{
|
||||
// get session id
|
||||
$session_id = $session->getID();
|
||||
|
||||
// get rider id
|
||||
if ($session->getRider() != null)
|
||||
{
|
||||
$rider_id = $session->getRider()->getID();
|
||||
|
||||
// key for redis
|
||||
$redis_key = 'rider.id.' . $session_id;
|
||||
$output->writeln('key: ' . $redis_key);
|
||||
|
||||
// set to redis cache
|
||||
// not sure if regular key value or hash. if hash, what name?
|
||||
// for now, use regular key value
|
||||
// $this->redis->hset($redis_key, $redis_key, $rider_id);
|
||||
$this->redis->set($redis_key, $rider_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue