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
bca6a333
Commit
bca6a333
authored
Nov 05, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #140
parent
c8f86652
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
42 deletions
+27
-42
sess_redis.go
session/sess_redis.go
+27
-42
No files found.
session/sess_redis.go
View file @
bca6a333
...
...
@@ -58,21 +58,12 @@ func (rs *RedisSessionStore) SessionID() string {
func
(
rs
*
RedisSessionStore
)
SessionRelease
()
{
defer
rs
.
c
.
Close
()
keys
,
err
:=
redis
.
Values
(
rs
.
c
.
Do
(
"HKEYS"
,
rs
.
sid
))
if
err
==
nil
{
for
_
,
key
:=
range
keys
{
if
val
,
ok
:=
rs
.
values
[
key
];
ok
{
rs
.
c
.
Do
(
"HSET"
,
rs
.
sid
,
key
,
val
)
rs
.
Delete
(
key
)
}
else
{
rs
.
c
.
Do
(
"HDEL"
,
rs
.
sid
,
key
)
}
}
}
if
len
(
rs
.
values
)
>
0
{
for
k
,
v
:=
range
rs
.
values
{
rs
.
c
.
Do
(
"HSET"
,
rs
.
sid
,
k
,
v
)
b
,
err
:=
encodeGob
(
rs
.
values
)
if
err
!=
nil
{
return
}
rs
.
c
.
Do
(
"SET"
,
rs
.
sid
,
string
(
b
))
}
}
...
...
@@ -123,31 +114,27 @@ func (rp *RedisProvider) SessionInit(maxlifetime int64, savePath string) error {
func
(
rp
*
RedisProvider
)
SessionRead
(
sid
string
)
(
SessionStore
,
error
)
{
c
:=
rp
.
poollist
.
Get
()
//if str, err := redis.String(c.Do("GET", sid)); err != nil || str == "" {
if
str
,
err
:=
redis
.
String
(
c
.
Do
(
"HGET"
,
sid
,
sid
));
err
!=
nil
||
str
==
""
{
//c.Do("SET", sid, sid, rp.maxlifetime)
c
.
Do
(
"HSET"
,
sid
,
sid
,
rp
.
maxlifetime
)
if
existed
,
err
:=
redis
.
Int
(
c
.
Do
(
"EXISTS"
,
sid
));
err
!=
nil
||
existed
==
0
{
c
.
Do
(
"SET"
,
sid
)
}
c
.
Do
(
"EXPIRE"
,
sid
,
rp
.
maxlifetime
)
kvs
,
err
:=
redis
.
Values
(
c
.
Do
(
"HGETALL"
,
sid
))
vals
:=
make
(
map
[
interface
{}]
interface
{})
var
key
interface
{}
if
err
==
nil
{
for
k
,
v
:=
range
kvs
{
if
k
%
2
==
0
{
key
=
v
}
else
{
vals
[
key
]
=
v
}
kvs
,
err
:=
redis
.
String
(
c
.
Do
(
"GET"
,
sid
))
var
kv
map
[
interface
{}]
interface
{}
if
len
(
kvs
)
==
0
{
kv
=
make
(
map
[
interface
{}]
interface
{})
}
else
{
kv
,
err
=
decodeGob
([]
byte
(
kvs
))
if
err
!=
nil
{
return
nil
,
err
}
}
rs
:=
&
RedisSessionStore
{
c
:
c
,
sid
:
sid
,
values
:
vals
}
rs
:=
&
RedisSessionStore
{
c
:
c
,
sid
:
sid
,
values
:
kv
}
return
rs
,
nil
}
func
(
rp
*
RedisProvider
)
SessionExist
(
sid
string
)
bool
{
c
:=
rp
.
poollist
.
Get
()
if
str
,
err
:=
redis
.
String
(
c
.
Do
(
"HGET"
,
sid
,
sid
));
err
!=
nil
||
str
==
""
{
if
existed
,
err
:=
redis
.
Int
(
c
.
Do
(
"EXISTS"
,
sid
));
err
!=
nil
||
existed
==
0
{
return
false
}
else
{
return
true
...
...
@@ -156,24 +143,22 @@ func (rp *RedisProvider) SessionExist(sid string) bool {
func
(
rp
*
RedisProvider
)
SessionRegenerate
(
oldsid
,
sid
string
)
(
SessionStore
,
error
)
{
c
:=
rp
.
poollist
.
Get
()
if
str
,
err
:=
redis
.
String
(
c
.
Do
(
"HGET"
,
oldsid
,
oldsid
));
err
!=
nil
||
str
==
""
{
c
.
Do
(
"
HSET"
,
oldsid
,
oldsid
,
rp
.
maxlifetime
)
if
existed
,
err
:=
redis
.
Int
(
c
.
Do
(
"EXISTS"
,
oldsid
));
err
!=
nil
||
existed
==
0
{
c
.
Do
(
"
SET"
,
oldsid
)
}
c
.
Do
(
"RENAME"
,
oldsid
,
sid
)
c
.
Do
(
"EXPIRE"
,
sid
,
rp
.
maxlifetime
)
kvs
,
err
:=
redis
.
Values
(
c
.
Do
(
"HGETALL"
,
sid
))
vals
:=
make
(
map
[
interface
{}]
interface
{})
var
key
interface
{}
if
err
==
nil
{
for
k
,
v
:=
range
kvs
{
if
k
%
2
==
0
{
key
=
v
}
else
{
vals
[
key
]
=
v
}
kvs
,
err
:=
redis
.
String
(
c
.
Do
(
"GET"
,
sid
))
var
kv
map
[
interface
{}]
interface
{}
if
len
(
kvs
)
==
0
{
kv
=
make
(
map
[
interface
{}]
interface
{})
}
else
{
kv
,
err
=
decodeGob
([]
byte
(
kvs
))
if
err
!=
nil
{
return
nil
,
err
}
}
rs
:=
&
RedisSessionStore
{
c
:
c
,
sid
:
sid
,
values
:
vals
}
rs
:=
&
RedisSessionStore
{
c
:
c
,
sid
:
sid
,
values
:
kv
}
return
rs
,
nil
}
...
...
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