如果我们想要在tp5.0.2中使用原生redis需要进行一些配置项
/application/config.php
// +----------------------------------------------------------------------
// | 缓存设置
// +----------------------------------------------------------------------
'cache' => [
// 驱动方式
'type' => 'redis',
// 缓存保存目录
'path' => CACHE_PATH,
// 缓存前缀
'prefix' => '',
// 缓存有效期 0表示永久缓存
'expire' => 0,
//服务器地址
'host'=>'127.0.0.1',
//端口号
'port' =>'6379',
//服务器密码
'password'=>'root'
],
在控制器中写入一个初始化redis的方法
use think\Cache;
use think\Db;
use Redis;
public function init()
{
//实例化redis
$redis = new Redis();
//选择服务器及端口
$