Home > PHP Framework > ThinkPHP > body text

What is thinkphp redis usage?

爱喝马黛茶的安东尼
Release: 2019-08-26 15:59:49
Original
3321 people have browsed it

What is thinkphp redis usage?

How to use redis in thinkphp5?

1. Set the application configuration file config.php

What is thinkphp redis usage?

type can be many categories: File, Redis, etc.

What is thinkphp redis usage?

Related recommendations: "ThinkPHP Tutorial"

2.thinkphp5 uses redis

New 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();
    }
}
Copy after login

3. Front-end display

New application/index/view/index.html

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

Output:

klc123
Copy after login

PS: When using redis, be sure to enable the redis server.

The above is the detailed content of What is thinkphp redis usage?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template