mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-29 13:51:37 +08:00
37 lines
807 B
PHP
37 lines
807 B
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
class Redis extends AbstractProvider
|
|
{
|
|
|
|
protected $serviceName = 'redis';
|
|
|
|
public function register()
|
|
{
|
|
$this->di->setShared($this->serviceName, function () {
|
|
|
|
$config = $this->getShared('config');
|
|
|
|
$redis = new \Redis();
|
|
|
|
$host = $config->redis->host ?: '127.0.0.1';
|
|
$port = $config->redis->port ?: 6379;
|
|
$persistent = $config->redis->persistent ?: false;
|
|
$auth = $config->redis->auth ?: null;
|
|
|
|
if ($persistent) {
|
|
$redis->pconnect($host, $port);
|
|
} else {
|
|
$redis->connect($host, $port);
|
|
}
|
|
|
|
if ($auth) {
|
|
$redis->auth($auth);
|
|
}
|
|
|
|
return $redis;
|
|
});
|
|
}
|
|
|
|
} |