安装redis后,先引入

use think\cache\driver\Redis;
控制器中写
//redis参数
$options= [
'host' => '127.0.0.1',
'port' => 6379,
'password' => 'xxxxx',
'select' => 0,
'timeout' => 0,
'expire' => 0,
'persistent' => false,
'prefix' => '',
];
$redis= new Redis($options);

$redis->set('name','你好啊');
$res = $redis->get('name'); //你好啊

世界上最美的风景,是自己努力的模样