thinkphp5 redis缓存驱动的简单应用

首先之前记得装好redis扩展

头文件

namespace app\index\controller;
use think\Controller;
use think\Db;
use think\view;
use think\Cache;
use think\cache\driver\Redis;

  //使用复合型缓存类型
    
    'cache' => [
     // 使用复合缓存类型

        'type'  =>  'complex',

        // 默认使用的缓存

        'default'   =>  [

            // 驱动方式

            'type'   => 'redis',

            // 缓存保存目录

            'path'   => CACHE_PATH,

扫描二维码关注公众号,回复: 4162595 查看本文章

        ],

        // 文件缓存

        'file'   =>  [

            // 驱动方式

            'type'   => 'file',

            // 设置不同的缓存保存目录

            'path'   => RUNTIME_PATH . 'file/',

        ],

        // redis缓存

        'redis'   =>  [

            // 驱动方式

            'type'   => 'redis',

            // 服务器地址

            'host'       => '39.108.37.76',
            'password'  => 'aabbccdd11',
            'port'      => 6379,
            'select'    => 0,

            'timeout'    => 3600,

            'expire'    => 3600,

            'persistent' => false,

            'prefix'    => '',

        ],
    ],

控制器

   public function redis()
    {
        // echo phpinfo();
        // exit;
        // $Redis=new Redis();
         Cache::store('redis')->set('name11','11111',3600);
        Cache::store('file')->set('nam','value111',3600);
        
        dump(Cache::store('file')->get('nam'));
        dump(Cache::get('name11'));
       
        exit;
    }

猜你喜欢

转载自blog.csdn.net/heyuqing32/article/details/82078752