zoukankan      html  css  js  c++  java
  • 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缓存一样

  • 相关阅读:
    移动端按钮居底
    easyui用KindEditor编辑器
    查找数组中与后面项匹配的和猴子选大王
    before和after的样式符号
    jq的select
    验证最多2位小数,1到10 不超过10 带两位小数的正则表达式
    在谷歌浏览器下vue的@input事件问题
    mvc项目+vue+vant【进行中】
    微商代理查询系统 开发完成,免费体验试用哦!
    淘宝出了个麻吉宝区块连产品,附带麻吉宝邀请码!
  • 原文地址:https://www.cnblogs.com/laijinquan/p/11048165.html
Copyright © 2011-2022 走看看