1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-29 22:01:38 +08:00

去除RedisProvider,获得redis实例用cache->getRedis()

This commit is contained in:
xiaochong0302 2019-12-19 18:18:15 +08:00
parent 38917697d0
commit a283296d35
7 changed files with 86 additions and 78 deletions

View File

@ -2,8 +2,6 @@
namespace App\Console\Tasks;
use App\Models\Chapter;
class MainTask extends Task
{
@ -12,13 +10,4 @@ class MainTask extends Task
echo "You are now flying with Phalcon CLI!";
}
public function okAction()
{
$chapter = Chapter::findFirstById(15224);
$chapter->duration = 123;
echo $chapter->duration;
}
}

View File

@ -24,6 +24,8 @@ class Cache extends AbstractProvider
'host' => $config->redis->host,
'port' => $config->redis->port,
'auth' => $config->redis->auth,
'index' => $config->redis->index,
'persistent' => $config->redis->persistent,
]);
return $backend;

View File

@ -1,37 +0,0 @@
<?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;
});
}
}

View File

@ -19,8 +19,9 @@ class Session extends AbstractProvider
'host' => $config->redis->host,
'port' => $config->redis->port,
'auth' => $config->redis->auth,
'index' => $config->session->index,
'lifetime' => $config->session->lifetime,
'index' => 1,
'persistent' => $config->redis->persistent,
]);
$session->start();

View File

@ -74,7 +74,6 @@ class ConsoleKernel extends Kernel
\App\Providers\EventsManager::class,
\App\Providers\Logger::class,
\App\Providers\MetaData::class,
\App\Providers\Redis::class,
\App\Providers\CliDispatcher::class,
];

View File

@ -53,7 +53,6 @@ class HttpKernel extends Kernel
\App\Providers\EventsManager::class,
\App\Providers\Logger::class,
\App\Providers\MetaData::class,
\App\Providers\Redis::class,
\App\Providers\Router::class,
\App\Providers\Security::class,
\App\Providers\Session::class,

View File

@ -7,39 +7,94 @@ $config = [];
*/
$config['env'] = 'pro';
$config['key'] = '223B08C66B0EC20466F513C4D9F8115D';
/**
* 加解密钥
*/
$config['key'] = 'mlq7jQ1Py8kTdW9m';
/**
* 所在时区
*/
$config['timezone'] = 'Asia/Shanghai';
$config['url'] = [
'base' => '/', // 必须以"/"结尾
'static' => '/static/', // 必须以"/"结尾
];
/**
* 网站根地址,必须以"/"结尾
*/
$config['url']['base'] = '/';
$config['db'] = [
'adapter' => 'Mysql',
'host' => 'localhost',
'username' => '',
'password' => '',
'dbname' => '',
'charset' => 'utf8',
];
/**
* 静态资源地址,必须以"/"结尾
*/
$config['url']['static'] = '/static/';
$config['redis'] = [
'host' => '127.0.0.1',
'port' => 6379,
'persistent' => false,
'auth' => '',
'index' => 0,
'lifetime' => 86400,
];
/**
* 数据库主机名
*/
$config['db']['host'] = 'mysql';
$config['session'] = [
'lifetime' => 7200,
];
/**
* 数据库名称
*/
$config['db']['dbname'] = 'ctc';
$config['log'] = [
'level' => Phalcon\Logger::INFO,
];
/**
* 数据库用户名
*/
$config['db']['username'] = 'ctc';
/**
* 数据库密码
*/
$config['db']['password'] = '1qaz2wsx3edc';
/**
* 数据库编码
*/
$config['db']['charset'] = 'utf8';
/**
* redis主机名
*/
$config['redis']['host'] = 'redis';
/**
* redis端口号
*/
$config['redis']['port'] = 6379;
/**
* redis链接密码
*/
$config['redis']['auth'] = '1qaz2wsx3edc';
/**
* 数据库编号
*/
$config['redis']['index'] = 0;
/**
* redis长链接
*/
$config['redis']['persistent'] = false;
/**
* 默认有限期(秒)
*/
$config['redis']['lifetime'] = 86400;
/**
* 会话有效期(秒)
*/
$config['session']['lifetime'] = 7200;
/**
* 数据库编号
*/
$config['session']['index'] = 1;
/**
* 日志级别
*/
$config['log']['level'] = Phalcon\Logger::INFO;
return $config;