Refactor RedisClientProvider #299
This commit is contained in:
parent
fb52b59ad9
commit
fe7cfe6c86
1 changed files with 25 additions and 18 deletions
|
|
@ -11,34 +11,41 @@ class RedisClientProvider
|
||||||
protected $host;
|
protected $host;
|
||||||
protected $port;
|
protected $port;
|
||||||
protected $password;
|
protected $password;
|
||||||
protected $env_flag;
|
|
||||||
|
|
||||||
public function __construct($scheme, $host, $port, $password, $env_flag)
|
public function __construct($scheme, $host, $port, $password)
|
||||||
{
|
{
|
||||||
$this->scheme = $scheme;
|
$this->scheme = $scheme;
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
$this->port = $port;
|
$this->port = $port;
|
||||||
$this->password = $password;
|
$this->password = $password;
|
||||||
$this->env_flag = $env_flag;
|
|
||||||
|
$this->connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function connect()
|
||||||
|
{
|
||||||
|
// if password is specified attempt connection
|
||||||
|
if (strlen($this->password) > 0)
|
||||||
|
{
|
||||||
|
$this->redis = new PredisClient([
|
||||||
|
"scheme" => $this->scheme,
|
||||||
|
"host" => $this->host,
|
||||||
|
"port" => $this->port,
|
||||||
|
"password" => $this->password]);
|
||||||
|
|
||||||
|
return $this->redis;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->redis = new PredisClient([
|
||||||
|
"scheme" => $this->scheme,
|
||||||
|
"host" => $this->host,
|
||||||
|
"port" => $this->port]);
|
||||||
|
|
||||||
|
return $this->redis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRedisClient()
|
public function getRedisClient()
|
||||||
{
|
{
|
||||||
if ($this->env_flag == 'dev')
|
|
||||||
{
|
|
||||||
$this->redis = new PredisClient([
|
|
||||||
"scheme"=>$this->scheme,
|
|
||||||
"host"=>$this->host,
|
|
||||||
"port"=>$this->port]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->redis = new PredisClient([
|
|
||||||
"scheme"=>$this->scheme,
|
|
||||||
"host"=>$this->host,
|
|
||||||
"port"=>$this->port,
|
|
||||||
"password"=>$this->password]);
|
|
||||||
}
|
|
||||||
return $this->redis;
|
return $this->redis;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue