thinkphp redis用法是什么

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼 原创
2019-08-26 15:59:49 2844浏览


thinkphp5如何使用redis?

1.设置应用配置文件config.php

q.jpg

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

w.jpg

相关推荐:《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('name','klc123');
        $data = $han->get('name');
        $this->assign('data',$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核实处理。