From 1a3263a4284cf919a181f4017ab7ad7d427663f7 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 14 May 2019 09:16:15 +0000 Subject: [PATCH] Use redis client provider to connect to redis. #206 --- config/services.yaml | 9 +++----- src/Service/APNSClient.php | 12 ++++------ src/Service/HubCounter.php | 4 ++-- src/Service/MQTTClient.php | 23 ++++--------------- ...edisClient.php => RedisClientProvider.php} | 2 +- 5 files changed, 16 insertions(+), 34 deletions(-) rename src/Service/{RedisClient.php => RedisClientProvider.php} (97%) diff --git a/config/services.yaml b/config/services.yaml index bf607603..6c7464e2 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -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)%" diff --git a/src/Service/APNSClient.php b/src/Service/APNSClient.php index 2fc02fe9..4a1e561b 100644 --- a/src/Service/APNSClient.php +++ b/src/Service/APNSClient.php @@ -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) { diff --git a/src/Service/HubCounter.php b/src/Service/HubCounter.php index 13388ecc..62d663ac 100644 --- a/src/Service/HubCounter.php +++ b/src/Service/HubCounter.php @@ -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 diff --git a/src/Service/MQTTClient.php b/src/Service/MQTTClient.php index 79fa9dac..aa0932a3 100644 --- a/src/Service/MQTTClient.php +++ b/src/Service/MQTTClient.php @@ -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) { diff --git a/src/Service/RedisClient.php b/src/Service/RedisClientProvider.php similarity index 97% rename from src/Service/RedisClient.php rename to src/Service/RedisClientProvider.php index 43323e0f..04ac1f80 100644 --- a/src/Service/RedisClient.php +++ b/src/Service/RedisClientProvider.php @@ -4,7 +4,7 @@ namespace App\Service; use Predis\Client as PredisClient; -class RedisClient +class RedisClientProvider { protected $redis; protected $scheme;