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

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

新聞中心

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

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

一、 REDIS安裝

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

1. 添加REDIS用戶:

adduser -M redis  

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

su - redis

3. 進入到 REDIS 安裝文件夾:

cd /usr/local/redis

4. 啟動 REDIS:

 make install && redis-server

二、 Redis 與 TP6 框架對接

1. 在`/extend/`文件夾下,新建一個文件`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()
{
//實例化model
$modelIndex = new \app\index\model\Index();
$modelIndex->set('key', 'value', 1800);
return '

操作緩存REDIS成功!

';
}
}
?>

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

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


分享文章:以TP6框架實現(xiàn)對Redis緩存的對接(tp對接redis)
瀏覽地址:http://m.5511xx.com/article/cdpjoep.html