thinkphp如何使用redis

thinkphp如何使用redis,第1张

thinkphp如何使用redis

thinkphp5如何使用redis?

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

type可以是很多分类File、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('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的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/701360.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-23
下一篇 2022-04-23

发表评论

登录后才能评论

评论列表(0条)

保存