1. mysql 配置
三、下一个文档中会有,这里略过
2. redis
2.1 cache.php 文件设置混合模式
<?phpuse think\facade\Env;return ['type' => 'complex',// 默认'default' => [// 驱动方式'type' => 'File',// 缓存保存目录'path' => '',// 缓存前缀'prefix' => '',// 缓存有效期 0表示永久缓存'expire' => 0,],// 文件'file' => [// 驱动方式'type' => 'File',// 缓存保存目录'path' => '',// 缓存前缀'prefix' => '',// 缓存有效期 0表示永久缓存'expire' => 0,],// redis'redis' => ['type' => 'redis','host' => '127.0.0.1','port' => '6379','password' => 'ailxma',// 全局缓存有效期(0为永久有效)'expire' => 0,// 缓存前缀'prefix' => '',],];
<?php// 测试连接 redispublic function testConnRedis(){// 使用Redis缓存$name = Cache::store('redis')->get('name');return json($name);}
结果:
2.2 使用 env 文件写入 redis 配置
cache.php 相关的配置
<?php// redis'redis' => ['type' => ENV::get('redis.redis_type'),'host' => ENV::get('redis.redis_host'),'port' => ENV::get('redis.redis_port'),'password' => ENV::get('redis.redis_password'),// 全局缓存有效期(0为永久有效)'expire' => ENV::get('redis.redis_expire'),// 缓存前缀'prefix' => ENV::get('redis.redis_prefix'),],
.env 新加入配置
[redis]redis_type = redisredis_host = 127.0.0.1redis_port = 6379redis_password = ailxmaredis_expire = 7200redis_prefix = ''
结果:
