Use redis client provider to connect to redis. #206

This commit is contained in:
Korina Cordero 2019-05-14 09:16:15 +00:00
parent 712d54abc5
commit 1a3263a428
5 changed files with 16 additions and 34 deletions

View file

@ -66,16 +66,13 @@ services:
App\Service\MQTTClient:
arguments:
$ip_address: "%env(MQTT_IP_ADDRESS)%"
$port: "%env(MQTT_PORT)%"
$cert: "%env(MQTT_CERT)%"
$redis_client: "@App\\Service\\RedisClientProvider"
App\Service\APNSClient:
arguments:
$ip_address: "%env(APNS_REDIS_IP_ADDRESS)%"
$port: "%env(APNS_REDIS_PORT)%"
$redis_client: "@App\\Service\\RedisClientProvider"
App\Service\RedisClient:
App\Service\RedisClientProvider:
arguments:
$scheme: "%env(REDIS_CLIENT_SCHEME)%"
$host: "%env(REDIS_CLIENT_HOST)%"

View file

@ -5,7 +5,6 @@ namespace App\Service;
use Mosquitto\Client as MosquittoClient;
use App\Entity\JobOrder;
use App\Ramcar\MobileOSType;
use Redis;
class APNSClient
{
@ -14,16 +13,15 @@ class APNSClient
// protected $mclient;
protected $redis;
public function __construct($ip_address, $port)
public function __construct(RedisClientProvider $redis_client)
{
$this->redis = new Redis();
$this->redis->connect($ip_address, $port);
$this->redis = $redis_client->getRedisClient();
}
public function __destruct()
{
public function __destruct()
{
// $this->mclient->disconnect();
}
}
public function push($token, $message)
{

View file

@ -15,10 +15,10 @@ class HubCounter
protected $em;
protected $redis;
public function __construct(EntityManagerInterface $em, RedisClient $rc)
public function __construct(EntityManagerInterface $em, RedisClientProvider $redis_client)
{
$this->em = $em;
$this->redis = $rc->getRedisClient();
$this->redis = $redis_client->getRedisClient();
}
// get rider key based on id

View file

@ -4,7 +4,6 @@ namespace App\Service;
use Mosquitto\Client as MosquittoClient;
use App\Entity\JobOrder;
use Redis;
class MQTTClient
{
@ -15,27 +14,15 @@ class MQTTClient
// protected $mclient;
protected $redis;
public function __construct($ip_address, $port, $cert)
public function __construct(RedisClientProvider $redis_client)
{
// we use redis now
// we have an mqtt server listening on redis and sending to mqtt
$this->redis = new Redis();
$this->redis->connect('127.0.0.1', 6379);
/*
error_log("connecting to mqtt server - $ip_address : $port");
error_log("using $cert");
$this->mclient = new MosquittoClient();
$this->mclient->setTlsCertificates($cert);
$this->mclient->setTlsOptions(MosquittoClient::SSL_VERIFY_NONE, 'tlsv1');
$this->mclient->connect($ip_address, $port);
*/
$this->redis = $redis_client->getRedisClient();
}
public function __destruct()
{
public function __destruct()
{
// $this->mclient->disconnect();
}
}
public function publish($channel, $message)
{

View file

@ -4,7 +4,7 @@ namespace App\Service;
use Predis\Client as PredisClient;
class RedisClient
class RedisClientProvider
{
protected $redis;
protected $scheme;