修改 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'=> 'think',
// 缓存目录
'path' => '../runtime/cache/',
],
'redis' => [
'type' => 'redis',
'host' => '39.xx4.xxx.xxx',
'port' => 6379,
'password' => 'xxxxxxxx',
// 全局缓存有效期(0为永久有效)
// 'expire'=> 0,
// 缓存前缀
'prefix'=> 'think:',
'timeout'=> 3600
],
// 添加更多的缓存类型设置
];
利用 composer 安装 predis/predis 依赖
composer require predis/predis
使用示例
public function redis(){
dump(Cache::store('redis')->set('sfdsf','yingying',1000000));
}