日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
以TP6框架實(shí)現(xiàn)對(duì)Redis緩存的對(duì)接(tp對(duì)接redis)

Redis緩存是高性能、高可用的NoSQL數(shù)據(jù)庫(kù),只支持單機(jī)和主從架構(gòu)部署,支持?jǐn)?shù)據(jù)的持久化,不受地理空間的限制。 REDIS緩存和TP6框架結(jié)合使用,可以實(shí)現(xiàn)對(duì)數(shù)據(jù)進(jìn)行更快、更安全的存取,減少數(shù)據(jù)庫(kù)的負(fù)載。

一、 REDIS安裝

首先要安裝REDIS,將 REDIS的安裝文件放在指定的文件夾內(nèi),然后依次執(zhí)行以下命令:

1. 添加REDIS用戶:

adduser -M redis  

2. 以redis用戶執(zhí)行redis:

su - redis

3. 進(jìn)入到 REDIS 安裝文件夾:

cd /usr/local/redis

4. 啟動(dòng) REDIS:

 make install && redis-server

二、 Redis 與 TP6 框架對(duì)接

1. 在`/extend/`文件夾下,新建一個(gè)文件`redis.php`,用來配置REDIS,在config里除加一句定義:


// redis.php
return [
'host' => '127.0.0.1',
'port' => '6379',
'password' => '',
];

2. 在根目錄中的 ` application/index/model/index.php` 里調(diào)用redis配置文件:


namespace app\index\model;

use think\Model;

class Index extends Model
{
protected $redis = null;
public function __construct()
{
$conf = include EXTEND_PATH . 'redis.php';
$this->redis = new \Redis();
$this->redis->connect($conf['host'], $conf['port']);
$pwd = $conf['password'];
if (!empty($pwd)) {
$this->redis->auth($pwd);
}
}
public function set($key, $value, $time)
{
$res = $this->redis->setex($key, $time, $value);
return $res;
}
}
?>

3. 在根目錄中的 `application/index/controller/Index.php` 里調(diào)用 model 中 redis 的函數(shù):


namespace app\index\controller;

class Index
{
public function index()
{
//實(shí)例化model
$modelIndex = new \app\index\model\Index();
$modelIndex->set('key', 'value', 1800);
return '

操作緩存REDIS成功!

';
}
}
?>

結(jié)論:以上我們就實(shí)現(xiàn)了TP6框架中對(duì)REDIS緩存的對(duì)接,可以更快、更安全的存取數(shù)據(jù),減少數(shù)據(jù)庫(kù)的負(fù)載。

成都創(chuàng)新互聯(lián)科技公司主營(yíng):網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、小程序制作、成都軟件開發(fā)、網(wǎng)頁(yè)設(shè)計(jì)、微信開發(fā)、成都小程序開發(fā)、網(wǎng)站制作、網(wǎng)站開發(fā)等業(yè)務(wù),是專業(yè)的成都做小程序公司、成都網(wǎng)站建設(shè)公司、成都做網(wǎng)站的公司。創(chuàng)新互聯(lián)公司集小程序制作創(chuàng)意,網(wǎng)站制作策劃,畫冊(cè)、網(wǎng)頁(yè)、VI設(shè)計(jì),網(wǎng)站、軟件、微信、小程序開發(fā)于一體。


當(dāng)前標(biāo)題:以TP6框架實(shí)現(xiàn)對(duì)Redis緩存的對(duì)接(tp對(duì)接redis)
文章URL:http://www.5511xx.com/article/cdpjoep.html