欢迎光临
我们一直在努力

tp5如何安装配置使用redis

tp5安装配置使用redis的方法:

1.php安装redis扩展。

2.在tp里找到config.php配置文件,再找到cache,修改成如下配置。

'cache' => [

// 选择模式

'type' => 'complex',

// 默认(vps云服务器文件缓存)

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

}

}

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。