tp5配置引入使用redis


1.首先你的php得是已經安裝了redis擴展的

2.在tp里找到config.php配置文件,找到cache,改成下面的樣子

    'cache'                  => [
        
              // 選擇模式

      'type'   => 'complex',

      // 默認(文件緩存)
      'default'=>[
        // 驅動方式
        'type'   => 'File',
        // 緩存保存目錄
        'path'   => CACHE_PATH,
        // 緩存前綴
        'prefix' => '',
        // 緩存有效期 0表示永久緩存
        'expire' => 0,

      ],
        
        //redis緩存設置
        'redis'   =>  [
            // 驅動方式
            'type'   => 'redis',
            // 服務器地址
            'host'   => '127.0.0.1',  //redis服務器ip
            'password' => '',
            'port'   => '6379',
            'password'=> "",
            'timeout' => 3600
        ], 
        
    ],

 

3.控制器里寫上以下代碼測試一下

<?php
namespace app\index\controller;

class Index
{
    public $redis;
    
    public function __construct(){
        $this->redis = new \Redis();
        $this->redis->connect('127.0.0.1',6379);
    }    

    
    public function index()
    {
        $redis = $this->redis;
        echo $redis->ping();
    }
  
}

 


免責聲明!

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



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