thinkphp5.1+ 使用 Redis 快取
阿新 • • 發佈:2018-12-19
修改 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 <
[email protected]> // +---------------------------------------------------------------------- // +---------------------------------------------------------------------- // | 快取設定 // +---------------------------------------------------------------------- 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));
}