Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
O
Open-Platform
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杜宇森
Open-Platform
Commits
e0a268b9
Commit
e0a268b9
authored
Sep 01, 2021
by
UtopiaXC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🀄
修改redis失效切换
parent
0a60f1b6
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
12 deletions
+36
-12
.env.example
.env.example
+15
-6
SiteProfileMiddleware.php
app/Http/Middleware/View/SiteProfileMiddleware.php
+7
-3
UserAuthMiddleware.php
app/Http/Middleware/View/UserAuthMiddleware.php
+8
-3
constants.php
config/System/constants.php
+4
-0
database.php
config/database.php
+2
-0
No files found.
.env.example
View file @
e0a268b9
# 平台名称,用于数据库前缀等
APP_NAME=utopia_open_platform
# 发送邮件时的展示名
APP_SHOW_NAME="Utopia Open Platform"
APP_ENV=local
APP_KEY=
APP_DEBUG=
fals
e
APP_DEBUG=
tru
e
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_LEVEL=debug
# MySQL配置
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
...
...
@@ -24,17 +27,23 @@ SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
# Redis配置
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
# 是否使用Redis,如果为false则不检测Redis直接采用Cache文件,为true则连接Redis超时后才会转为Cache文件
REDIS_USE=true
# 本平台大量依赖于Redis,建议将Redis超时时间在机器性能允许范围内设短一点,超时后将转为Cache,自动切换后会导致状态丢失
REDIS_TIMEOUT=0.1
#邮箱配置
MAIL_MAILER=smtp
MAIL_HOST=
mailhog
MAIL_PORT=
1025
MAIL_USERNAME=
null
MAIL_PASSWORD=
null
MAIL_HOST=
smtpdm.aliyun.com
MAIL_PORT=
80
MAIL_USERNAME=
yourname@yourdomain
MAIL_PASSWORD=
your_smtp_password
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=
null
MAIL_FROM_ADDRESS=
your_account
MAIL_FROM_NAME="${APP_SHOW_NAME}"
AWS_ACCESS_KEY_ID=
...
...
app/Http/Middleware/View/SiteProfileMiddleware.php
View file @
e0a268b9
...
...
@@ -24,11 +24,15 @@ class SiteProfileMiddleware
{
//通过Redis获取网站配置信息,如果没有则存入Redis
if
(
env
(
\EnvKey
::
REDIS_USE
,
false
)
==
true
)
{
try
{
$site_profile
=
json_decode
(
Redis
::
get
(
RedisCacheKey
::
SITE_PROFILE
),
true
);
}
catch
(
ConnectionException
$e
)
{
$site_profile
=
json_decode
(
Cache
::
get
(
RedisCacheKey
::
SITE_PROFILE
),
true
);
}
}
else
{
$site_profile
=
json_decode
(
Cache
::
get
(
RedisCacheKey
::
SITE_PROFILE
),
true
);
}
if
(
!
$site_profile
)
{
$site_profile
=
SiteProfile
::
all
();
try
{
...
...
app/Http/Middleware/View/UserAuthMiddleware.php
View file @
e0a268b9
...
...
@@ -23,11 +23,16 @@ class UserAuthMiddleware
if
(
!
$token
)
{
$request
->
attributes
->
add
([
HeaderKey
::
LOGIN_STATUS
=>
false
]);
}
if
(
env
(
\EnvKey
::
REDIS_USE
,
false
)
==
true
)
{
try
{
$user
=
json_decode
(
Redis
::
get
(
\RedisCacheKey
::
USER_TOKEN
.
$token
),
true
);
}
catch
(
ConnectionException
$e
)
{
$user
=
json_decode
(
\Cache
::
get
(
\RedisCacheKey
::
USER_TOKEN
.
$token
),
true
);
}
}
else
{
$user
=
json_decode
(
\Cache
::
get
(
\RedisCacheKey
::
USER_TOKEN
.
$token
),
true
);
}
if
(
!
$user
)
$request
->
attributes
->
add
([
HeaderKey
::
LOGIN_STATUS
=>
false
]);
else
...
...
config/System/constants.php
View file @
e0a268b9
...
...
@@ -71,3 +71,7 @@ class DefaultSiteProfile
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>'
;
}
class
EnvKey
{
const
REDIS_USE
=
"REDIS_USE"
;
}
config/database.php
View file @
e0a268b9
...
...
@@ -132,6 +132,7 @@ return [
'password'
=>
env
(
'REDIS_PASSWORD'
,
null
),
'port'
=>
env
(
'REDIS_PORT'
,
'6379'
),
'database'
=>
env
(
'REDIS_DB'
,
'0'
),
'timeout'
=>
env
(
'REDIS_TIMEOUT'
,
0.05
)
],
'cache'
=>
[
...
...
@@ -140,6 +141,7 @@ return [
'password'
=>
env
(
'REDIS_PASSWORD'
,
null
),
'port'
=>
env
(
'REDIS_PORT'
,
'6379'
),
'database'
=>
env
(
'REDIS_CACHE_DB'
,
'1'
),
'timeout'
=>
env
(
'REDIS_TIMEOUT'
,
0.05
)
],
],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment