TP5配置操作redis

配置方式如下:

 'cache' =>  [
        // 使用复合缓存类型
        'type'  =>  'complex',
        // 默认使用的缓存
        'default'   =>  [
            // 驱动方式
            'type'   => 'File',
            // 缓存保存目录
            'path'   => CACHE_PATH,
        ],
        // 文件缓存
        'file'   =>  [
            // 驱动方式
            'type'   => 'file',
            // 设置不同的缓存保存目录
            'path'   => RUNTIME_PATH . 'file/',
        ],
        // redis缓存
        'redis'   =>  [
            // 驱动方式
            'type'   => 'redis',
            // 服务器地址
            'host'       => '192.168.1.100',
        ],
    ],

使用符合缓存类型时,需要根据需要使用store方法切换缓存。

当使用

Cache::set('name', 'value');
Cache::get('name');

的时候,使用的是default缓存标识的缓存配置。如果需要切换到其它的缓存标识操作,可以使用:

// 切换到file操作
Cache::store('file')->set('name','value');
Cache::get('name');
// 切换到redis操作
Cache::store('redis')->set('name','value');
Cache::get('name');

 

posted on 2019-04-04 18:04  duo飞  阅读(4548)  评论(0编辑  收藏  举报