Home > Article > PHP Framework > How thinkphp uses redis
How to use redis in thinkphp5?
1. Set the application configuration file config.php
type can be many categories: File, Redis, etc.
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('name','klc123'); $data = $han->get('name'); $this->assign('data',$data); return view(); } }
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>
Output:
klc123
PS: When using redis, be sure to enable the redis server.
The above is the detailed content of How thinkphp uses redis. For more information, please follow other related articles on the PHP Chinese website!