首頁  >  文章  >  php框架  >  thinkphp redis用法是什麼

thinkphp redis用法是什麼

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼原創
2019-08-26 15:59:493272瀏覽

thinkphp redis用法是什麼

thinkphp5如何使用redis?

1.設定應用程式設定檔config.php

thinkphp redis用法是什麼

#type可以是很多分類File、Redis等等。

thinkphp redis用法是什麼

相關推薦:《ThinkPHP教學

2.thinkphp5使用redis

新application/index/ controller/index.php

<?php
namespace app\index\controller;
use think\Controller;
use think\Cache;
class Index extends Controller
{
    public function index()
    {    
        $han = new Cache;
        // halt($han);
        $han->set(&#39;name&#39;,&#39;klc123&#39;);
        $data = $han->get(&#39;name&#39;);
        $this->assign(&#39;data&#39;,$data);
        return view();
    }
}

3.前端顯示

新application/index/view/index.html

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>index/index</title>
</head>
<body>
    {$data}
</body>
</html>

輸出:

klc123

PS:使用redis,注意開啟redis伺服器。

以上是thinkphp redis用法是什麼的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn