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');

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM