redis tp5

tp5如何安装配置使用redis

小新
528
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
看了该问题的人还看了