34eff4cc by Pengfei Xue

bugfix, delete the sid if it's values is empty

* regenerate sid, if the old key doesn't exists, set the new one directly
1 parent d014ccfb
......@@ -60,14 +60,15 @@ func (rs *RedisSessionStore) SessionID() string {
}
func (rs *RedisSessionStore) SessionRelease(w http.ResponseWriter) {
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
}
c := rs.p.Get()
defer c.Close()
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{}
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!