1、在php.ini中配置扩展,需要确保存在此扩展文件
extension=php_redis.dll
2、在项目目录config下修改cache.php,内容如下
<?php
return [
// 缓存配置为复合类型
'type' => 'complex',
'default' => [
'type' => 'file',
// 全局缓存有效期(0为永久有效)
'expire'=> 0,
// 缓存前缀
'prefix'=> 'think',
// 缓存目录
'path' => 'd://keteBaoRuntime/cache/',
],
'redis' => [
'type' => 'redis',
'host' => '127.0.0.1',
// 全局缓存有效期(0为永久有效)
'expire'=> 0,
// 缓存前缀
'prefix'=> '',
]
];
3、控制器中引入Cache类
use think\facade\Cache;
4、代码中存入缓存
Cache::store('redis')->set('iotOffLineArr1',json_encode($iotInLineArr),3600);
5、代码中取出缓存
$res = json_decode(Cache::store('redis')->get('iotOffLineArr1'),true)