mirror of
https://github.com/astaxie/beego.git
synced 2024-11-01 00:00:54 +00:00
bugfix, delete the sid if it's values is empty
* regenerate sid, if the old key doesn't exists, set the new one directly
This commit is contained in:
parent
d014ccfb8e
commit
34eff4cc1f
@ -60,14 +60,15 @@ func (rs *RedisSessionStore) SessionID() string {
|
||||
}
|
||||
|
||||
func (rs *RedisSessionStore) SessionRelease(w http.ResponseWriter) {
|
||||
// if rs.values is empty, return directly
|
||||
if len(rs.values) < 1 {
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
@ -155,8 +156,15 @@ func (rp *RedisProvider) SessionRegenerate(oldsid, sid string) (SessionStore, er
|
||||
c := rp.poollist.Get()
|
||||
defer c.Close()
|
||||
|
||||
c.Do("RENAME", oldsid, sid)
|
||||
c.Do("EXPIRE", sid, rp.maxlifetime)
|
||||
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)
|
||||
}
|
||||
|
||||
kvs, err := redis.String(c.Do("GET", sid))
|
||||
var kv map[interface{}]interface{}
|
||||
|
Loading…
Reference in New Issue
Block a user