TP5 Thinkphp5.0 操作redis

一 、//连接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数据存取

Cache::set('名称',数据,有效期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);

}

猜你喜欢

转载自blog.csdn.net/qq_35979073/article/details/79355447