1. 下载安装redis
2. 配置php.ini,加上一句话
extension=php_redis.dll
3.修改tp5里面config中的cache.php文件
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
// | 缓存设置
// +----------------------------------------------------------------------
return [
// 缓存配置为复合类型
'type' => 'complex',
'default' => [
'type' => 'file',
// 全局缓存有效期(0为永久有效)
'expire'=> 0,
// 缓存前缀
'prefix'=> '',
// 缓存目录
'path' => '../runtime/cache/',
],
'redis' => [
// 类型
'type' => 'redis',
// 地址
'host' => '127.0.0.1',
// 全局缓存有效期(0为永久有效)
'expire'=> 0,
// 缓存前缀
'prefix'=> '',
// 端口
'port'=> '6379',
// 用户名
'username' => 'root ',
// 密码
'password' => '',
],
];
4.使用
Cache::store('redis')->get('name'); // 验证码校验成功一次后,将当前缓存中对应手机号的验证码删除 Cache::store('redis')->set('name','value',12000);