Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
41332acf
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
17
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yii2_fecshop
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
41332acf
编写于
1月 02, 2018
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
session services,新增SessionRedis方式的实现
上级
ab350636
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
158 addition
and
2 deletion
+158
-2
config/services/Session.php
config/services/Session.php
+1
-1
models/redis/SessionStorage.php
models/redis/SessionStorage.php
+31
-0
services/Order.php
services/Order.php
+1
-1
services/session/SessionRedis.php
services/session/SessionRedis.php
+125
-0
未找到文件。
config/services/Session.php
浏览文件 @
41332acf
...
...
@@ -18,7 +18,7 @@ return [
'updateTimeLimit'
=>
600
,
// 【不可以设置phpsession】默认为php session,只有当 \Yii::$app->user->enableSession == false时,下面的设置才有效。
// 存储引擎 mongodb mysqldb redis
'storage'
=>
'SessionMysqldb'
,
'storage'
=>
'Session
Redis'
,
//'Session
Mysqldb',
//'childService' => [
...
...
models/redis/SessionStorage.php
0 → 100644
浏览文件 @
41332acf
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace
fecshop\models\redis
;
use
yii\redis\ActiveRecord
;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
SessionStorage
extends
ActiveRecord
{
public
function
attributes
()
{
return
[
'id'
,
'session_uuid'
,
'session_key'
,
'session_value'
,
'session_timeout'
,
'session_updated_at'
];
}
/**
* relations can not be defined via a table as there are not tables in redis. You can only define relations via other records.
*/
}
services/Order.php
浏览文件 @
41332acf
...
...
@@ -99,7 +99,7 @@ class Order extends Service
$this
->
status_processing
=>
$this
->
status_processing
,
$this
->
status_dispatched
=>
$this
->
status_dispatched
,
$this
->
status_refunded
=>
$this
->
status_refunded
,
$this
->
status_complete
=>
$this
->
status_complete
,
$this
->
status_complete
d
=>
$this
->
status_completed
,
];
}
...
...
services/session/SessionRedis.php
浏览文件 @
41332acf
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace
fecshop\services\session
;
use
Yii
;
use
fecshop\services\Service
;
//use fecshop\models\mysqldb\SessionStorage;
/**
* redis session services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
SessionRedis
extends
Service
implements
SessionInterface
{
protected
$_sessionModelName
=
'\fecshop\models\redis\SessionStorage'
;
protected
$_sessionModel
;
public
function
init
(){
parent
::
init
();
list
(
$this
->
_sessionModelName
,
$this
->
_sessionModel
)
=
\
Yii
::
mapGet
(
$this
->
_sessionModelName
);
}
public
function
set
(
$key
,
$val
,
$timeout
){
$uuid
=
Yii
::
$service
->
session
->
getUUID
();
$one
=
$this
->
_sessionModel
->
find
()
->
where
([
'session_uuid'
=>
$uuid
,
'session_key'
=>
$key
,
])
->
one
();
if
(
!
$one
[
'id'
]){
$one
=
new
$this
->
_sessionModelName
();
$one
[
'session_uuid'
]
=
$uuid
;
$one
[
'session_key'
]
=
$key
;
}
$one
[
'session_value'
]
=
$val
;
$one
[
'session_timeout'
]
=
$timeout
;
$one
[
'session_updated_at'
]
=
time
();
$one
->
save
();
return
true
;
}
public
function
get
(
$key
,
$reflush
){
$uuid
=
Yii
::
$service
->
session
->
getUUID
();
$one
=
$this
->
_sessionModel
->
find
()
->
where
([
'session_uuid'
=>
$uuid
,
'session_key'
=>
$key
,
])
->
one
();
if
(
$one
[
'id'
]){
$timeout
=
$one
[
'session_timeout'
];
$updated_at
=
$one
[
'session_updated_at'
];
if
(
$updated_at
+
$timeout
>
time
()){
if
(
$reflush
){
$one
[
'session_updated_at'
]
=
time
();
$one
->
save
();
}
return
$one
[
'session_value'
];
}
}
}
public
function
remove
(
$key
){
$uuid
=
Yii
::
$service
->
session
->
getUUID
();
$one
=
$this
->
_sessionModel
->
find
()
->
where
([
'session_uuid'
=>
$uuid
,
'session_key'
=>
$key
,
])
->
one
();
if
(
$one
[
'id'
]){
$one
->
delete
();
return
true
;
}
}
/**
*
*/
public
function
destroy
(){
if
(
!
Yii
::
$app
->
user
->
isGuest
){
$identity
=
Yii
::
$app
->
user
->
identity
;
$identity
->
access_token
=
''
;
$identity
->
access_token_created_at
=
null
;
$identity
->
save
();
}
$uuid
=
Yii
::
$service
->
session
->
getUUID
();
$result
=
$this
->
_sessionModel
->
deleteAll
([
'session_uuid'
=>
$uuid
,
]);
$access_token_created_at
=
$identity
->
access_token_created_at
;
$timeout
=
Yii
::
$service
->
session
->
timeout
;
if
(
$access_token_created_at
+
$timeout
>
time
()){
return
$accessToken
;
}
return
true
;
}
public
function
setFlash
(
$key
,
$val
,
$timeout
){
return
$this
->
set
(
$key
,
$val
,
$timeout
);
}
public
function
getFlash
(
$key
){
$uuid
=
Yii
::
$service
->
session
->
getUUID
();
$one
=
$this
->
_sessionModel
->
find
()
->
where
([
'session_uuid'
=>
$uuid
,
'session_key'
=>
$key
,
])
->
one
();
if
(
$one
[
'id'
]){
$timeout
=
$one
[
'session_timeout'
];
$updated_at
=
$one
[
'session_updated_at'
];
if
(
$updated_at
+
$timeout
>
time
()){
$val
=
$one
[
'session_value'
];
$one
->
delete
();
return
$val
;
}
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录