laravel redis缓存的使用方法
2018年4月18日前期配置
1 2 |
composer require "predis/predis:~1.0" //添加驱动 QUEUE_DRIVER=redis //配置.env |
引入类
从您想使用缓存的地方引入这个类,就可以按照下面的代码直接使用了
1 |
use Illuminate\Support\Facades\Cache; |
使用方法
1 2 3 4 5 6 |
if (!Cache::has('home.index.secret')) { //判断这个数据是否在redis中存在 ...<code> Cache::put('home.index.secret', $secret, 30); //添加到reids缓存中,30指的是缓存分钟,$secret是从数据中查询出来的数据 } else { $secret = Cache::get('home.index.secret'); //从数据库中查询该数据 } |