Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jamesyang1999
ShopXO
提交
c8906037
ShopXO
项目概览
jamesyang1999
/
ShopXO
与 Fork 源项目一致
Fork自
纵之格 / ShopXO
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
ShopXO
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c8906037
编写于
9月 26, 2020
作者:
D
devil
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
数据缓存与session配置分离
上级
b6b7f717
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
130 addition
and
43 deletion
+130
-43
application/admin/controller/Site.php
application/admin/controller/Site.php
+62
-3
application/admin/view/default/site/cache.html
application/admin/view/default/site/cache.html
+53
-25
application/service/BaseConfigHandleService.php
application/service/BaseConfigHandleService.php
+10
-10
config/shopxo.sql
config/shopxo.sql
+5
-5
未找到文件。
application/admin/controller/Site.php
浏览文件 @
c8906037
...
...
@@ -205,11 +205,25 @@ class Site extends Common
// 缓存
case
'cache'
:
if
((
isset
(
$params
[
'common_session_is_use_cache'
])
&&
$params
[
'common_session_is_use_cache'
]
==
1
)
||
(
isset
(
$params
[
'common_data_is_use_cache'
])
&&
$params
[
'common_data_is_use_cache'
]
==
1
))
// session是否使用缓存
if
(
isset
(
$params
[
'common_session_is_use_cache'
])
&&
$params
[
'common_session_is_use_cache'
]
==
1
)
{
if
(
!
extension_loaded
(
'redis'
))
// 连接测试
$ret
=
$this
->
RedisCheckConnectPing
(
$params
[
'common_cache_session_redis_host'
],
$params
[
'common_cache_session_redis_port'
],
$params
[
'common_cache_session_redis_password'
]);
if
(
$ret
[
'code'
]
!=
0
)
{
return
DataReturn
(
'请先安装redis扩展'
,
-
1
);
return
$ret
;
}
}
// 数据是否使用缓存
if
(
isset
(
$params
[
'common_data_is_use_cache'
])
&&
$params
[
'common_data_is_use_cache'
]
==
1
)
{
// 连接测试
$ret
=
$this
->
RedisCheckConnectPing
(
$params
[
'common_cache_data_redis_host'
],
$params
[
'common_cache_data_redis_port'
],
$params
[
'common_cache_data_redis_password'
]);
if
(
$ret
[
'code'
]
!=
0
)
{
return
$ret
;
}
}
break
;
...
...
@@ -257,5 +271,50 @@ class Site extends Common
return
$ret
;
}
/**
* redis连接测试
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-09-26
* @desc description
* @param [string] $host [连接地址]
* @param [int] $port [端口]
* @param [string] $password [密码]
*/
private
function
RedisCheckConnectPing
(
$host
,
$port
,
$password
)
{
// 参数处理
$host
=
empty
(
$host
)
?
'127.0.0.1'
:
$host
;
$port
=
empty
(
$port
)
?
6379
:
$port
;
$password
=
empty
(
$password
)
?
''
:
$password
;
// 是否已安装redis扩展
if
(
!
extension_loaded
(
'redis'
))
{
return
DataReturn
(
'请先安装redis扩展'
,
-
1
);
}
// 捕获异常
try
{
// 连接redis
$redis
=
new
\
Redis
();
$redis
->
connect
(
$host
,
$port
);
if
(
$password
!=
''
)
{
$redis
->
auth
(
$password
);
}
}
catch
(
\
Exception
$e
)
{
return
DataReturn
(
'redis连接失败['
.
$e
->
getMessage
()
.
']'
,
-
1
);
}
// 检测是否连接成功
if
(
$redis
->
ping
())
{
return
DataReturn
(
'redis连接成功'
,
0
);
}
return
DataReturn
(
'redis连接失败'
,
-
1
);
}
}
?>
\ No newline at end of file
application/admin/view/default/site/cache.html
浏览文件 @
c8906037
...
...
@@ -9,10 +9,17 @@
<!-- form start -->
<form
class=
"am-form form-validation view-save"
action=
"{{:MyUrl('admin/site/save')}}"
method=
"POST"
request-type=
"ajax-url"
request-value=
"{{:MyUrl('admin/site/index', ['nav_type'=>'cache'])}}"
enctype=
"multipart/form-data"
>
<!-- 基础配置 -->
<div
class=
"am-alert am-alert-warning"
data-am-alert
>
<button
type=
"button"
class=
"am-close"
>
×
</button>
<p>
1. 默认使用的文件缓存、使用Redis缓存PHP需要先安装Redis扩展
</p>
<p>
2. 请确保Redis服务稳定性(Session使用缓存后、服务不稳定可能导致后台也无法登录)
</p>
<p>
3. 如遇到Redis服务异常无法登录管理后台、可进入数据库[
<strong
class=
"am-text-danger"
>
{{:config('database.prefix')}}config
</strong>
]表修改配置、然后删除[
<strong
class=
"am-text-danger"
>
config
</strong>
]目录下[
<strong
class=
"am-text-danger"
>
session.php,cache.php
</strong>
]文件
</p>
</div>
<!-- Session缓存配置 -->
<div
class=
"am-panel am-panel-default"
>
<div
class=
"am-panel-hd"
>
<h3
class=
"am-panel-title"
>
基础
配置
</h3>
<h3
class=
"am-panel-title"
>
Session缓存
配置
</h3>
</div>
<div
class=
"am-panel-bd"
>
<div
class=
"am-form-group"
>
...
...
@@ -24,52 +31,73 @@
</select>
</div>
<div
class=
"am-form-group"
>
<label>
{{$data.common_data_is_use_cache.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_data_is_use_cache.describe}}
</span></label>
<select
name=
"{{$data.common_data_is_use_cache.only_tag}}"
class=
"am-radius chosen-select"
data-validation-message=
"{{$data.common_data_is_use_cache.error_tips}}"
required
>
{{foreach $common_is_text_list as $v}}
<option
value=
"{{$v.id}}"
{{
if
isset
($
data
['
common_data_is_use_cache
']['
value
'])
and
$
data
['
common_data_is_use_cache
']['
value
']
eq
$
v
['
id
']}}
selected
{{/
if
}}
>
{{$v.name}}
</option>
{{/foreach}}
</select>
<label>
{{$data.common_cache_session_redis_host.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_cache_session_redis_host.describe}}
</span></label>
<input
type=
"text"
name=
"{{$data.common_cache_session_redis_host.only_tag}}"
placeholder=
"{{$data.common_cache_session_redis_host.describe}}"
data-validation-message=
"{{$data.common_cache_session_redis_host.error_tips}}"
class=
"am-radius"
{{
if
!
empty
($
data
)}}
value=
"{{$data.common_cache_session_redis_host.value}}"
{{/
if
}}
/>
</div>
<div
class=
"am-form-group"
>
<label>
{{$data.common_cache_session_redis_port.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_cache_session_redis_port.describe}}
</span></label>
<input
type=
"text"
name=
"{{$data.common_cache_session_redis_port.only_tag}}"
placeholder=
"{{$data.common_cache_session_redis_port.describe}}"
data-validation-message=
"{{$data.common_cache_session_redis_port.error_tips}}"
class=
"am-radius"
{{
if
!
empty
($
data
)}}
value=
"{{$data.common_cache_session_redis_port.value}}"
{{/
if
}}
/>
</div>
<div
class=
"am-form-group"
>
<label>
{{$data.common_cache_session_redis_password.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_cache_session_redis_password.describe}}
</span></label>
<input
type=
"text"
name=
"{{$data.common_cache_session_redis_password.only_tag}}"
placeholder=
"{{$data.common_cache_session_redis_password.describe}}"
data-validation-message=
"{{$data.common_cache_session_redis_password.error_tips}}"
class=
"am-radius"
{{
if
!
empty
($
data
)}}
value=
"{{$data.common_cache_session_redis_password.value}}"
{{/
if
}}
/>
</div>
<div
class=
"am-form-group"
>
<label>
{{$data.common_cache_session_redis_expire.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_cache_session_redis_expire.describe}}
</span></label>
<div
class=
"am-input-group am-input-group-sm"
>
<input
type=
"number"
min=
"0"
name=
"{{$data.common_cache_session_redis_expire.only_tag}}"
placeholder=
"{{$data.common_cache_session_redis_expire.name}}"
data-validation-message=
"{{$data.common_cache_session_redis_expire.error_tips}}"
class=
"am-radius"
{{
if
!
empty
($
data
)}}
value=
"{{$data.common_cache_session_redis_expire.value}}"
{{/
if
}}
/>
<span
class=
"am-input-group-btn"
>
<button
class=
"am-btn am-btn-default"
type=
"button"
>
秒
</button>
</span>
</div>
</div>
<div
class=
"am-form-group"
>
<label>
{{$data.common_cache_session_redis_prefix.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_cache_session_redis_prefix.describe}}
</span></label>
<input
type=
"text"
name=
"{{$data.common_cache_session_redis_prefix.only_tag}}"
placeholder=
"{{$data.common_cache_session_redis_prefix.describe}}"
data-validation-message=
"{{$data.common_cache_session_redis_prefix.error_tips}}"
class=
"am-radius"
{{
if
!
empty
($
data
)}}
value=
"{{$data.common_cache_session_redis_prefix.value}}"
{{/
if
}}
/>
</div>
</div>
</div>
<!--
Redis
配置 -->
<!--
数据缓存
配置 -->
<div
class=
"am-panel am-panel-default"
>
<div
class=
"am-panel-hd"
>
<h3
class=
"am-panel-title"
>
Redis
配置
</h3>
<h3
class=
"am-panel-title"
>
数据缓存
配置
</h3>
</div>
<div
class=
"am-panel-bd"
>
<div
class=
"am-form-group"
>
<label>
{{$data.common_cache_redis_host.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_cache_redis_host.describe}}
</span></label>
<input
type=
"text"
name=
"{{$data.common_cache_redis_host.only_tag}}"
placeholder=
"{{$data.common_cache_redis_host.describe}}"
data-validation-message=
"{{$data.common_cache_redis_host.error_tips}}"
class=
"am-radius"
{{
if
!
empty
($
data
)}}
value=
"{{$data.common_cache_redis_host.value}}"
{{/
if
}}
/>
<label>
{{$data.common_data_is_use_cache.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_data_is_use_cache.describe}}
</span></label>
<select
name=
"{{$data.common_data_is_use_cache.only_tag}}"
class=
"am-radius chosen-select"
data-validation-message=
"{{$data.common_data_is_use_cache.error_tips}}"
required
>
{{foreach $common_is_text_list as $v}}
<option
value=
"{{$v.id}}"
{{
if
isset
($
data
['
common_data_is_use_cache
']['
value
'])
and
$
data
['
common_data_is_use_cache
']['
value
']
eq
$
v
['
id
']}}
selected
{{/
if
}}
>
{{$v.name}}
</option>
{{/foreach}}
</select>
</div>
<div
class=
"am-form-group"
>
<label>
{{$data.common_cache_data_redis_host.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_cache_data_redis_host.describe}}
</span></label>
<input
type=
"text"
name=
"{{$data.common_cache_data_redis_host.only_tag}}"
placeholder=
"{{$data.common_cache_data_redis_host.describe}}"
data-validation-message=
"{{$data.common_cache_data_redis_host.error_tips}}"
class=
"am-radius"
{{
if
!
empty
($
data
)}}
value=
"{{$data.common_cache_data_redis_host.value}}"
{{/
if
}}
/>
</div>
<div
class=
"am-form-group"
>
<label>
{{$data.common_cache_
redis_port.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_cache
_redis_port.describe}}
</span></label>
<input
type=
"text"
name=
"{{$data.common_cache_
redis_port.only_tag}}"
placeholder=
"{{$data.common_cache_redis_port.describe}}"
data-validation-message=
"{{$data.common_cache_redis_port.error_tips}}"
class=
"am-radius"
{{
if
!
empty
($
data
)}}
value=
"{{$data.common_cache
_redis_port.value}}"
{{/
if
}}
/>
<label>
{{$data.common_cache_
data_redis_port.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_cache_data
_redis_port.describe}}
</span></label>
<input
type=
"text"
name=
"{{$data.common_cache_
data_redis_port.only_tag}}"
placeholder=
"{{$data.common_cache_data_redis_port.describe}}"
data-validation-message=
"{{$data.common_cache_data_redis_port.error_tips}}"
class=
"am-radius"
{{
if
!
empty
($
data
)}}
value=
"{{$data.common_cache_data
_redis_port.value}}"
{{/
if
}}
/>
</div>
<div
class=
"am-form-group"
>
<label>
{{$data.common_cache_
redis_password.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_cache
_redis_password.describe}}
</span></label>
<input
type=
"text"
name=
"{{$data.common_cache_
redis_password.only_tag}}"
placeholder=
"{{$data.common_cache_redis_password.describe}}"
data-validation-message=
"{{$data.common_cache_redis_password.error_tips}}"
class=
"am-radius"
{{
if
!
empty
($
data
)}}
value=
"{{$data.common_cache
_redis_password.value}}"
{{/
if
}}
/>
<label>
{{$data.common_cache_
data_redis_password.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_cache_data
_redis_password.describe}}
</span></label>
<input
type=
"text"
name=
"{{$data.common_cache_
data_redis_password.only_tag}}"
placeholder=
"{{$data.common_cache_data_redis_password.describe}}"
data-validation-message=
"{{$data.common_cache_data_redis_password.error_tips}}"
class=
"am-radius"
{{
if
!
empty
($
data
)}}
value=
"{{$data.common_cache_data
_redis_password.value}}"
{{/
if
}}
/>
</div>
<div
class=
"am-form-group"
>
<label>
{{$data.common_cache_
redis_expire.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_cache
_redis_expire.describe}}
</span></label>
<label>
{{$data.common_cache_
data_redis_expire.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_cache_data
_redis_expire.describe}}
</span></label>
<div
class=
"am-input-group am-input-group-sm"
>
<input
type=
"number"
min=
"0"
name=
"{{$data.common_cache_
redis_expire.only_tag}}"
placeholder=
"{{$data.common_cache_redis_expire.name}}"
data-validation-message=
"{{$data.common_cache_redis_expire.error_tips}}"
class=
"am-radius"
{{
if
!
empty
($
data
)}}
value=
"{{$data.common_cache
_redis_expire.value}}"
{{/
if
}}
/>
<input
type=
"number"
min=
"0"
name=
"{{$data.common_cache_
data_redis_expire.only_tag}}"
placeholder=
"{{$data.common_cache_data_redis_expire.name}}"
data-validation-message=
"{{$data.common_cache_data_redis_expire.error_tips}}"
class=
"am-radius"
{{
if
!
empty
($
data
)}}
value=
"{{$data.common_cache_data
_redis_expire.value}}"
{{/
if
}}
/>
<span
class=
"am-input-group-btn"
>
<button
class=
"am-btn am-btn-default"
type=
"button"
>
秒
</button>
</span>
</div>
<div
class=
"am-alert am-alert-warning"
data-am-alert
>
<button
type=
"button"
class=
"am-close"
>
×
</button>
<p>
1. session下过期时间默认为3600秒
</p>
<p>
2. 数据缓存下过期时间默认0(表示默认永久缓存)
</p>
</div>
</div>
<div
class=
"am-form-group"
>
<label>
{{$data.common_cache_
redis_prefix.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_cache
_redis_prefix.describe}}
</span></label>
<input
type=
"text"
name=
"{{$data.common_cache_
redis_prefix.only_tag}}"
placeholder=
"{{$data.common_cache_redis_prefix.describe}}"
data-validation-message=
"{{$data.common_cache_redis_prefix.error_tips}}"
class=
"am-radius"
{{
if
!
empty
($
data
)}}
value=
"{{$data.common_cache
_redis_prefix.value}}"
{{/
if
}}
/>
<label>
{{$data.common_cache_
data_redis_prefix.name}}
<span
class=
"am-form-group-label-tips"
>
{{$data.common_cache_data
_redis_prefix.describe}}
</span></label>
<input
type=
"text"
name=
"{{$data.common_cache_
data_redis_prefix.only_tag}}"
placeholder=
"{{$data.common_cache_data_redis_prefix.describe}}"
data-validation-message=
"{{$data.common_cache_data_redis_prefix.error_tips}}"
class=
"am-radius"
{{
if
!
empty
($
data
)}}
value=
"{{$data.common_cache_data
_redis_prefix.value}}"
{{/
if
}}
/>
</div>
</div>
</div>
...
...
application/service/BaseConfigHandleService.php
浏览文件 @
c8906037
...
...
@@ -63,15 +63,15 @@ class BaseConfigHandleService
// 使用redis
'type'
=>
'redis'
,
// 连接地址
'host'
=>
MyC
(
'common_cache_redis_host'
,
'127.0.0.1'
,
true
),
'host'
=>
MyC
(
'common_cache_
session_
redis_host'
,
'127.0.0.1'
,
true
),
// 端口号
'port'
=>
MyC
(
'common_cache_redis_port'
,
6379
,
true
),
'port'
=>
MyC
(
'common_cache_
session_
redis_port'
,
6379
,
true
),
// 密码
'password'
=>
MyC
(
'common_cache_redis_password'
,
''
,
true
),
'password'
=>
MyC
(
'common_cache_
session_
redis_password'
,
''
,
true
),
// 全局缓存有效期、默认3600秒
'expire'
=>
MyC
(
'common_cache_redis_expire'
,
3600
,
true
),
'expire'
=>
MyC
(
'common_cache_
session_
redis_expire'
,
3600
,
true
),
// 缓存前缀
'prefix'
=>
MyC
(
'common_cache_redis_prefix'
,
'shopxo'
,
true
),
'prefix'
=>
MyC
(
'common_cache_
session_
redis_prefix'
,
'shopxo'
,
true
),
];
}
else
{
$config
=
[
...
...
@@ -116,15 +116,15 @@ class BaseConfigHandleService
// 使用redis
'type'
=>
'redis'
,
// 连接地址
'host'
=>
MyC
(
'common_cache_redis_host'
,
'127.0.0.1'
,
true
),
'host'
=>
MyC
(
'common_cache_
data_
redis_host'
,
'127.0.0.1'
,
true
),
// 端口号
'port'
=>
MyC
(
'common_cache_redis_port'
,
6379
,
true
),
'port'
=>
MyC
(
'common_cache_
data_
redis_port'
,
6379
,
true
),
// 密码
'password'
=>
MyC
(
'common_cache_redis_password'
,
''
,
true
),
'password'
=>
MyC
(
'common_cache_
data_
redis_password'
,
''
,
true
),
// 全局缓存有效期(0为永久有效)
'expire'
=>
MyC
(
'common_cache_redis_expire'
,
0
,
true
),
'expire'
=>
MyC
(
'common_cache_
data_
redis_expire'
,
0
,
true
),
// 缓存前缀
'prefix'
=>
MyC
(
'common_cache_redis_prefix'
,
'shopxo'
,
true
),
'prefix'
=>
MyC
(
'common_cache_
data_
redis_prefix'
,
'shopxo'
,
true
),
];
}
else
{
...
...
config/shopxo.sql
浏览文件 @
c8906037
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录