首页 >php框架 >ThinkPHP > 正文

thinkphp如何使用redis

原创2019-08-22 16:09:37010585

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中文网其它相关文章!

php中文网最新课程二维码

声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理

  • 相关标签:thinkphp 使用 redis
  • 相关文章

    相关视频


    网友评论

    文明上网理性发言,请遵守 新闻评论服务协议

    我要评论
  • 专题推荐

    推荐视频教程
  • LAMP兄弟连ThinkPHP视频教程LAMP兄弟连ThinkPHP视频教程
  • ThinkPHP基础实战视频教程ThinkPHP基础实战视频教程
  • ThinkPHP5基础视频教程ThinkPHP5基础视频教程
  • 视频教程分类