1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-22 22:50:50 +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:
Pengfei Xue 2014-01-25 10:55:49 +08:00
parent d014ccfb8e
commit 34eff4cc1f

View File

@ -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{}