溫馨提示×

tp5如何安裝配置使用redis

小新
550
2021-02-19 10:57:12
欄目: 云計算

tp5如何安裝配置使用redis

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.最后在控制器中使用以下代碼測試。

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

}

}

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女