本文来和大家详细聊聊关于ThinkPHP6的相关知识,在ThinkPHP6中,应该如何使用Redis呢?本文列举了详细示例代码与解析,建议先收藏再观看。

一起聊聊在ThinkPHP6中如何使用Redis?
1、在TP6项目设置Redis参数配置
config/cache.php
<?php
use think\facade\Env;
// +----------------------------------------------------------------------
// | 缓存设置
// +----------------------------------------------------------------------
return [
// 默认缓存驱动
'default' => Env::get('cache.driver', 'file'),
// 缓存连接方式配置
'stores' => [
'file' => [
// 驱动方式
'type' => 'File',
// 缓存保存目录
'path' => '',
// 缓存前缀
'prefix' => '',
// 缓存有效期 0表示永久缓存
'expire' => 0,
// 缓存标签前缀
'tag_prefix' => 'tag:',
// 序列化机制 例如 ['serialize', 'unserialize']
'serialize' => [],
],
//新增redis
'redis' => [
// 驱动方式
'type' => 'redis',
// 服务器地址
'host' => '127.0.0.1',
'password' => '',//如果没有设置密码为空
],
// 更多的缓存连接
],
];
2、使用Redis
<?php
namespace app\api\controller;
use think\cache\driver\Redis;
use think\facade\Config;
class Test
{
public function test()
{
$redis = new Redis(Config::get('cache.stores.redis'));
$redis->set('pasawu', 'test');
$pasa = $redis->get('pasawu');
dd($pasa);
}
}
以上就是关于在ThinkPHP6中如何使用Redis的详细解析了,翼速应用平台内有更多相关资讯,欢迎查阅!


发布需求
我来说两句