thinkphp5.1+ 使用 Redis 緩存


修改 config/cache.php 將其配置成多個緩存類型,示例

 1 <?php
 2 // +----------------------------------------------------------------------
 3 // | ThinkPHP [ WE CAN DO IT JUST THINK ]
 4 // +----------------------------------------------------------------------
 5 // | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
 6 // +----------------------------------------------------------------------
 7 // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
 8 // +----------------------------------------------------------------------
 9 // | Author: liu21st <liu21st@gmail.com>
10 // +----------------------------------------------------------------------
11  
12 // +----------------------------------------------------------------------
13 // | 緩存設置
14 // +----------------------------------------------------------------------
15  
16 return [
17  
18     // 緩存配置為復合類型
19     'type'  =>  'complex',
20  
21     'default'    =>    [
22         'type'    =>    'file',
23         // 全局緩存有效期(0為永久有效)
24         'expire'=>  0,
25         // 緩存前綴
26         'prefix'=>  'think',
27         // 緩存目錄
28         'path'  =>  '../runtime/cache/',
29     ],
30  
31     'redis'    =>    [
32         'type'    =>    'redis',
33         'host'    =>    '39.xx4.xxx.xxx',
34         'port' => 6379,
35         'password' => 'xxxxxxxx',
36         // 全局緩存有效期(0為永久有效)
37         //        'expire'=>  0,
38         // 緩存前綴
39         'prefix'=>  'think:',
40         'timeout'=> 3600
41     ],
42     // 添加更多的緩存類型設置
43  
44 ];

記得安裝php的redis擴展,我其他博客有說,我這里就不說了

使用示例:

 public function redis(){
 
            dump(Cache::store('redis')->set('sfdsf','yingying',1000000));
        }

其他的用法和file緩存一樣


免責聲明!

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



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