Use redis client provider to connect to redis. #206
This commit is contained in:
parent
712d54abc5
commit
1a3263a428
5 changed files with 16 additions and 34 deletions
|
|
@ -66,16 +66,13 @@ services:
|
||||||
|
|
||||||
App\Service\MQTTClient:
|
App\Service\MQTTClient:
|
||||||
arguments:
|
arguments:
|
||||||
$ip_address: "%env(MQTT_IP_ADDRESS)%"
|
$redis_client: "@App\\Service\\RedisClientProvider"
|
||||||
$port: "%env(MQTT_PORT)%"
|
|
||||||
$cert: "%env(MQTT_CERT)%"
|
|
||||||
|
|
||||||
App\Service\APNSClient:
|
App\Service\APNSClient:
|
||||||
arguments:
|
arguments:
|
||||||
$ip_address: "%env(APNS_REDIS_IP_ADDRESS)%"
|
$redis_client: "@App\\Service\\RedisClientProvider"
|
||||||
$port: "%env(APNS_REDIS_PORT)%"
|
|
||||||
|
|
||||||
App\Service\RedisClient:
|
App\Service\RedisClientProvider:
|
||||||
arguments:
|
arguments:
|
||||||
$scheme: "%env(REDIS_CLIENT_SCHEME)%"
|
$scheme: "%env(REDIS_CLIENT_SCHEME)%"
|
||||||
$host: "%env(REDIS_CLIENT_HOST)%"
|
$host: "%env(REDIS_CLIENT_HOST)%"
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ namespace App\Service;
|
||||||
use Mosquitto\Client as MosquittoClient;
|
use Mosquitto\Client as MosquittoClient;
|
||||||
use App\Entity\JobOrder;
|
use App\Entity\JobOrder;
|
||||||
use App\Ramcar\MobileOSType;
|
use App\Ramcar\MobileOSType;
|
||||||
use Redis;
|
|
||||||
|
|
||||||
class APNSClient
|
class APNSClient
|
||||||
{
|
{
|
||||||
|
|
@ -14,16 +13,15 @@ class APNSClient
|
||||||
// protected $mclient;
|
// protected $mclient;
|
||||||
protected $redis;
|
protected $redis;
|
||||||
|
|
||||||
public function __construct($ip_address, $port)
|
public function __construct(RedisClientProvider $redis_client)
|
||||||
{
|
{
|
||||||
$this->redis = new Redis();
|
$this->redis = $redis_client->getRedisClient();
|
||||||
$this->redis->connect($ip_address, $port);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
// $this->mclient->disconnect();
|
// $this->mclient->disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function push($token, $message)
|
public function push($token, $message)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@ class HubCounter
|
||||||
protected $em;
|
protected $em;
|
||||||
protected $redis;
|
protected $redis;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em, RedisClient $rc)
|
public function __construct(EntityManagerInterface $em, RedisClientProvider $redis_client)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
$this->redis = $rc->getRedisClient();
|
$this->redis = $redis_client->getRedisClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
// get rider key based on id
|
// get rider key based on id
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ namespace App\Service;
|
||||||
|
|
||||||
use Mosquitto\Client as MosquittoClient;
|
use Mosquitto\Client as MosquittoClient;
|
||||||
use App\Entity\JobOrder;
|
use App\Entity\JobOrder;
|
||||||
use Redis;
|
|
||||||
|
|
||||||
class MQTTClient
|
class MQTTClient
|
||||||
{
|
{
|
||||||
|
|
@ -15,27 +14,15 @@ class MQTTClient
|
||||||
// protected $mclient;
|
// protected $mclient;
|
||||||
protected $redis;
|
protected $redis;
|
||||||
|
|
||||||
public function __construct($ip_address, $port, $cert)
|
public function __construct(RedisClientProvider $redis_client)
|
||||||
{
|
{
|
||||||
// we use redis now
|
$this->redis = $redis_client->getRedisClient();
|
||||||
// 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);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
// $this->mclient->disconnect();
|
// $this->mclient->disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function publish($channel, $message)
|
public function publish($channel, $message)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace App\Service;
|
||||||
|
|
||||||
use Predis\Client as PredisClient;
|
use Predis\Client as PredisClient;
|
||||||
|
|
||||||
class RedisClient
|
class RedisClientProvider
|
||||||
{
|
{
|
||||||
protected $redis;
|
protected $redis;
|
||||||
protected $scheme;
|
protected $scheme;
|
||||||
Loading…
Reference in a new issue