Commit e0a268b9 authored by UtopiaXC's avatar UtopiaXC

🀄 修改redis失效切换

parent 0a60f1b6
# 平台名称,用于数据库前缀等
APP_NAME=utopia_open_platform APP_NAME=utopia_open_platform
# 发送邮件时的展示名
APP_SHOW_NAME="Utopia Open Platform" APP_SHOW_NAME="Utopia Open Platform"
APP_ENV=local APP_ENV=local
APP_KEY= APP_KEY=
APP_DEBUG=false APP_DEBUG=true
APP_URL=http://localhost APP_URL=http://localhost
LOG_CHANNEL=stack LOG_CHANNEL=stack
LOG_LEVEL=debug LOG_LEVEL=debug
# MySQL配置
DB_CONNECTION=mysql DB_CONNECTION=mysql
DB_HOST=127.0.0.1 DB_HOST=127.0.0.1
DB_PORT=3306 DB_PORT=3306
...@@ -24,17 +27,23 @@ SESSION_LIFETIME=120 ...@@ -24,17 +27,23 @@ SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1 MEMCACHED_HOST=127.0.0.1
# Redis配置
REDIS_HOST=127.0.0.1 REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null REDIS_PASSWORD=null
REDIS_PORT=6379 REDIS_PORT=6379
# 是否使用Redis,如果为false则不检测Redis直接采用Cache文件,为true则连接Redis超时后才会转为Cache文件
REDIS_USE=true
# 本平台大量依赖于Redis,建议将Redis超时时间在机器性能允许范围内设短一点,超时后将转为Cache,自动切换后会导致状态丢失
REDIS_TIMEOUT=0.1
#邮箱配置
MAIL_MAILER=smtp MAIL_MAILER=smtp
MAIL_HOST=mailhog MAIL_HOST=smtpdm.aliyun.com
MAIL_PORT=1025 MAIL_PORT=80
MAIL_USERNAME=null MAIL_USERNAME=yourname@yourdomain
MAIL_PASSWORD=null MAIL_PASSWORD=your_smtp_password
MAIL_ENCRYPTION=null MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null MAIL_FROM_ADDRESS=your_account
MAIL_FROM_NAME="${APP_SHOW_NAME}" MAIL_FROM_NAME="${APP_SHOW_NAME}"
AWS_ACCESS_KEY_ID= AWS_ACCESS_KEY_ID=
......
...@@ -24,11 +24,15 @@ class SiteProfileMiddleware ...@@ -24,11 +24,15 @@ class SiteProfileMiddleware
{ {
//通过Redis获取网站配置信息,如果没有则存入Redis //通过Redis获取网站配置信息,如果没有则存入Redis
if (env(\EnvKey::REDIS_USE, false) == true) {
try { try {
$site_profile = json_decode(Redis::get(RedisCacheKey::SITE_PROFILE), true); $site_profile = json_decode(Redis::get(RedisCacheKey::SITE_PROFILE), true);
} catch (ConnectionException $e) { } catch (ConnectionException $e) {
$site_profile = json_decode(Cache::get(RedisCacheKey::SITE_PROFILE), true); $site_profile = json_decode(Cache::get(RedisCacheKey::SITE_PROFILE), true);
} }
}else{
$site_profile = json_decode(Cache::get(RedisCacheKey::SITE_PROFILE), true);
}
if (!$site_profile) { if (!$site_profile) {
$site_profile = SiteProfile::all(); $site_profile = SiteProfile::all();
try { try {
......
...@@ -23,11 +23,16 @@ class UserAuthMiddleware ...@@ -23,11 +23,16 @@ class UserAuthMiddleware
if (!$token) { if (!$token) {
$request->attributes->add([HeaderKey::LOGIN_STATUS => false]); $request->attributes->add([HeaderKey::LOGIN_STATUS => false]);
} }
if (env(\EnvKey::REDIS_USE, false) == true) {
try { try {
$user = json_decode(Redis::get(\RedisCacheKey::USER_TOKEN . $token), true); $user = json_decode(Redis::get(\RedisCacheKey::USER_TOKEN . $token), true);
} catch (ConnectionException $e) { } catch (ConnectionException $e) {
$user = json_decode(\Cache::get(\RedisCacheKey::USER_TOKEN . $token), true); $user = json_decode(\Cache::get(\RedisCacheKey::USER_TOKEN . $token), true);
} }
}else{
$user = json_decode(\Cache::get(\RedisCacheKey::USER_TOKEN . $token), true);
}
if (!$user) if (!$user)
$request->attributes->add([HeaderKey::LOGIN_STATUS => false]); $request->attributes->add([HeaderKey::LOGIN_STATUS => false]);
else else
......
...@@ -71,3 +71,7 @@ class DefaultSiteProfile ...@@ -71,3 +71,7 @@ class DefaultSiteProfile
const SITE_URL = 'http://localhost'; const SITE_URL = 'http://localhost';
const WEB_FOOTER='Copyright ©2021 <a target="_blank" href="https://www.utopiaxc.cn/">UtopiaXC</a> All Rights Reserved | Powered By <a href="https://github.com/UtopiaXC/Utopia-Open-Platform" target="_blank">Utopia Open Platform</a>'; const WEB_FOOTER='Copyright ©2021 <a target="_blank" href="https://www.utopiaxc.cn/">UtopiaXC</a> All Rights Reserved | Powered By <a href="https://github.com/UtopiaXC/Utopia-Open-Platform" target="_blank">Utopia Open Platform</a>';
} }
class EnvKey{
const REDIS_USE="REDIS_USE";
}
...@@ -132,6 +132,7 @@ return [ ...@@ -132,6 +132,7 @@ return [
'password' => env('REDIS_PASSWORD', null), 'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'), 'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_DB', '0'), 'database' => env('REDIS_DB', '0'),
'timeout'=>env('REDIS_TIMEOUT',0.05)
], ],
'cache' => [ 'cache' => [
...@@ -140,6 +141,7 @@ return [ ...@@ -140,6 +141,7 @@ return [
'password' => env('REDIS_PASSWORD', null), 'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'), 'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_CACHE_DB', '1'), 'database' => env('REDIS_CACHE_DB', '1'),
'timeout'=>env('REDIS_TIMEOUT',0.05)
], ],
], ],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment