一 、//連接redis
use think\Cache;
可以用Tp5自帶的Cache操作redis
function redis(){
? ? $options = [
? ? ? 'type'? => 'redis',//指定類型
? ? ? 'password'=>'asdfghjkl',
? ? ?'prefix' => 'sbn-',
? ? ?'host'? ? ? => '127.0.0.1',
? ];
? ?Cache::init($options);//初始化
}
二、redis數(shù)據(jù)存取
Cache::set('名稱',數(shù)據(jù),有效期0為不過期);
Cache::set('名稱');
public function test(){
? ? ? ini_set ('memory_limit', '800M');
? ? ? $vo = Db::name('cun')->order('id asc')->select();
? ? ? Cache::set('listtest',$vo,0);
? ? ?// $vo=json_encode($vo);也可以存json字符串
? ? ?$res = Cache::get('listtest');
? ? dump($res);
}