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:
parent
38917697d0
commit
a283296d35
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Console\Tasks;
|
namespace App\Console\Tasks;
|
||||||
|
|
||||||
use App\Models\Chapter;
|
|
||||||
|
|
||||||
class MainTask extends Task
|
class MainTask extends Task
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -12,13 +10,4 @@ class MainTask extends Task
|
|||||||
echo "You are now flying with Phalcon CLI!";
|
echo "You are now flying with Phalcon CLI!";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function okAction()
|
|
||||||
{
|
|
||||||
$chapter = Chapter::findFirstById(15224);
|
|
||||||
|
|
||||||
$chapter->duration = 123;
|
|
||||||
|
|
||||||
echo $chapter->duration;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,8 @@ class Cache extends AbstractProvider
|
|||||||
'host' => $config->redis->host,
|
'host' => $config->redis->host,
|
||||||
'port' => $config->redis->port,
|
'port' => $config->redis->port,
|
||||||
'auth' => $config->redis->auth,
|
'auth' => $config->redis->auth,
|
||||||
|
'index' => $config->redis->index,
|
||||||
|
'persistent' => $config->redis->persistent,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $backend;
|
return $backend;
|
||||||
|
@ -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;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -19,8 +19,9 @@ class Session extends AbstractProvider
|
|||||||
'host' => $config->redis->host,
|
'host' => $config->redis->host,
|
||||||
'port' => $config->redis->port,
|
'port' => $config->redis->port,
|
||||||
'auth' => $config->redis->auth,
|
'auth' => $config->redis->auth,
|
||||||
|
'index' => $config->session->index,
|
||||||
'lifetime' => $config->session->lifetime,
|
'lifetime' => $config->session->lifetime,
|
||||||
'index' => 1,
|
'persistent' => $config->redis->persistent,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$session->start();
|
$session->start();
|
||||||
|
@ -74,7 +74,6 @@ class ConsoleKernel extends Kernel
|
|||||||
\App\Providers\EventsManager::class,
|
\App\Providers\EventsManager::class,
|
||||||
\App\Providers\Logger::class,
|
\App\Providers\Logger::class,
|
||||||
\App\Providers\MetaData::class,
|
\App\Providers\MetaData::class,
|
||||||
\App\Providers\Redis::class,
|
|
||||||
\App\Providers\CliDispatcher::class,
|
\App\Providers\CliDispatcher::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -53,7 +53,6 @@ class HttpKernel extends Kernel
|
|||||||
\App\Providers\EventsManager::class,
|
\App\Providers\EventsManager::class,
|
||||||
\App\Providers\Logger::class,
|
\App\Providers\Logger::class,
|
||||||
\App\Providers\MetaData::class,
|
\App\Providers\MetaData::class,
|
||||||
\App\Providers\Redis::class,
|
|
||||||
\App\Providers\Router::class,
|
\App\Providers\Router::class,
|
||||||
\App\Providers\Security::class,
|
\App\Providers\Security::class,
|
||||||
\App\Providers\Session::class,
|
\App\Providers\Session::class,
|
||||||
|
@ -7,39 +7,94 @@ $config = [];
|
|||||||
*/
|
*/
|
||||||
$config['env'] = 'pro';
|
$config['env'] = 'pro';
|
||||||
|
|
||||||
$config['key'] = '223B08C66B0EC20466F513C4D9F8115D';
|
/**
|
||||||
|
* 加解密钥
|
||||||
|
*/
|
||||||
|
$config['key'] = 'mlq7jQ1Py8kTdW9m';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所在时区
|
||||||
|
*/
|
||||||
$config['timezone'] = 'Asia/Shanghai';
|
$config['timezone'] = 'Asia/Shanghai';
|
||||||
|
|
||||||
$config['url'] = [
|
/**
|
||||||
'base' => '/', // 必须以"/"结尾
|
* 网站根地址,必须以"/"结尾
|
||||||
'static' => '/static/', // 必须以"/"结尾
|
*/
|
||||||
];
|
$config['url']['base'] = '/';
|
||||||
|
|
||||||
$config['db'] = [
|
/**
|
||||||
'adapter' => 'Mysql',
|
* 静态资源地址,必须以"/"结尾
|
||||||
'host' => 'localhost',
|
*/
|
||||||
'username' => '',
|
$config['url']['static'] = '/static/';
|
||||||
'password' => '',
|
|
||||||
'dbname' => '',
|
|
||||||
'charset' => 'utf8',
|
|
||||||
];
|
|
||||||
|
|
||||||
$config['redis'] = [
|
/**
|
||||||
'host' => '127.0.0.1',
|
* 数据库主机名
|
||||||
'port' => 6379,
|
*/
|
||||||
'persistent' => false,
|
$config['db']['host'] = 'mysql';
|
||||||
'auth' => '',
|
|
||||||
'index' => 0,
|
|
||||||
'lifetime' => 86400,
|
|
||||||
];
|
|
||||||
|
|
||||||
$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;
|
return $config;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user