Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
3f0ec5c0
Commit
3f0ec5c0
authored
Jan 28, 2014
by
傅小黑
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' of
git://github.com/astaxie/beego
into develop
parents
0e287232
2fb57583
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
15 deletions
+32
-15
controller.go
controller.go
+1
-0
sess_redis.go
session/sess_redis.go
+31
-15
No files found.
controller.go
View file @
3f0ec5c0
...
...
@@ -398,6 +398,7 @@ func (c *Controller) SessionRegenerateID() {
// DestroySession cleans session data and session cookie.
func
(
c
*
Controller
)
DestroySession
()
{
c
.
Ctx
.
Input
.
CruSession
.
Flush
()
GlobalSessions
.
SessionDestroy
(
c
.
Ctx
.
ResponseWriter
,
c
.
Ctx
.
Request
)
}
...
...
session/sess_redis.go
View file @
3f0ec5c0
...
...
@@ -16,7 +16,7 @@ var MAX_POOL_SIZE = 100
var
redisPool
chan
redis
.
Conn
type
RedisSessionStore
struct
{
c
redis
.
Conn
p
*
redis
.
Pool
sid
string
lock
sync
.
RWMutex
values
map
[
interface
{}]
interface
{}
...
...
@@ -60,13 +60,21 @@ func (rs *RedisSessionStore) SessionID() string {
}
func
(
rs
*
RedisSessionStore
)
SessionRelease
(
w
http
.
ResponseWriter
)
{
defer
rs
.
c
.
Close
()
c
:=
rs
.
p
.
Get
()
defer
c
.
Close
()
// if rs.values is empty, return directly
if
len
(
rs
.
values
)
<
1
{
c
.
Do
(
"DEL"
,
rs
.
sid
)
return
}
b
,
err
:=
encodeGob
(
rs
.
values
)
if
err
!=
nil
{
return
}
rs
.
c
.
Do
(
"SET"
,
rs
.
sid
,
string
(
b
))
rs
.
c
.
Do
(
"EXPIRE"
,
rs
.
sid
,
rs
.
maxlifetime
)
c
.
Do
(
"SET"
,
rs
.
sid
,
string
(
b
),
"EX"
,
rs
.
maxlifetime
)
}
type
RedisProvider
struct
{
...
...
@@ -116,10 +124,8 @@ func (rp *RedisProvider) SessionInit(maxlifetime int64, savePath string) error {
func
(
rp
*
RedisProvider
)
SessionRead
(
sid
string
)
(
SessionStore
,
error
)
{
c
:=
rp
.
poollist
.
Get
()
if
existed
,
err
:=
redis
.
Int
(
c
.
Do
(
"EXISTS"
,
sid
));
err
!=
nil
||
existed
==
0
{
c
.
Do
(
"SET"
,
sid
)
}
c
.
Do
(
"EXPIRE"
,
sid
,
rp
.
maxlifetime
)
defer
c
.
Close
()
kvs
,
err
:=
redis
.
String
(
c
.
Do
(
"GET"
,
sid
))
var
kv
map
[
interface
{}]
interface
{}
if
len
(
kvs
)
==
0
{
...
...
@@ -130,13 +136,15 @@ func (rp *RedisProvider) SessionRead(sid string) (SessionStore, error) {
return
nil
,
err
}
}
rs
:=
&
RedisSessionStore
{
c
:
c
,
sid
:
sid
,
values
:
kv
,
maxlifetime
:
rp
.
maxlifetime
}
rs
:=
&
RedisSessionStore
{
p
:
rp
.
poollist
,
sid
:
sid
,
values
:
kv
,
maxlifetime
:
rp
.
maxlifetime
}
return
rs
,
nil
}
func
(
rp
*
RedisProvider
)
SessionExist
(
sid
string
)
bool
{
c
:=
rp
.
poollist
.
Get
()
defer
c
.
Close
()
if
existed
,
err
:=
redis
.
Int
(
c
.
Do
(
"EXISTS"
,
sid
));
err
!=
nil
||
existed
==
0
{
return
false
}
else
{
...
...
@@ -146,11 +154,18 @@ func (rp *RedisProvider) SessionExist(sid string) bool {
func
(
rp
*
RedisProvider
)
SessionRegenerate
(
oldsid
,
sid
string
)
(
SessionStore
,
error
)
{
c
:=
rp
.
poollist
.
Get
()
if
existed
,
err
:=
redis
.
Int
(
c
.
Do
(
"EXISTS"
,
oldsid
));
err
!=
nil
||
existed
==
0
{
c
.
Do
(
"SET"
,
oldsid
)
defer
c
.
Close
()
if
existed
,
_
:=
redis
.
Int
(
c
.
Do
(
"EXISTS"
,
oldsid
));
existed
==
0
{
// oldsid doesn't exists, set the new sid directly
// ignore error here, since if it return error
// the existed value will be 0
c
.
Do
(
"SET"
,
sid
,
""
,
"EX"
,
rp
.
maxlifetime
)
}
else
{
c
.
Do
(
"RENAME"
,
oldsid
,
sid
)
c
.
Do
(
"EXPIRE"
,
sid
,
rp
.
maxlifetime
)
}
c
.
Do
(
"RENAME"
,
oldsid
,
sid
)
c
.
Do
(
"EXPIRE"
,
sid
,
rp
.
maxlifetime
)
kvs
,
err
:=
redis
.
String
(
c
.
Do
(
"GET"
,
sid
))
var
kv
map
[
interface
{}]
interface
{}
if
len
(
kvs
)
==
0
{
...
...
@@ -161,13 +176,15 @@ func (rp *RedisProvider) SessionRegenerate(oldsid, sid string) (SessionStore, er
return
nil
,
err
}
}
rs
:=
&
RedisSessionStore
{
c
:
c
,
sid
:
sid
,
values
:
kv
,
maxlifetime
:
rp
.
maxlifetime
}
rs
:=
&
RedisSessionStore
{
p
:
rp
.
poollist
,
sid
:
sid
,
values
:
kv
,
maxlifetime
:
rp
.
maxlifetime
}
return
rs
,
nil
}
func
(
rp
*
RedisProvider
)
SessionDestroy
(
sid
string
)
error
{
c
:=
rp
.
poollist
.
Get
()
defer
c
.
Close
()
c
.
Do
(
"DEL"
,
sid
)
return
nil
}
...
...
@@ -178,7 +195,6 @@ func (rp *RedisProvider) SessionGC() {
//@todo
func
(
rp
*
RedisProvider
)
SessionAll
()
int
{
return
0
}
...
...
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