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 { ...@@ -60,14 +60,15 @@ func (rs *RedisSessionStore) SessionID() string {
60 } 60 }
61 61
62 func (rs *RedisSessionStore) SessionRelease(w http.ResponseWriter) { 62 func (rs *RedisSessionStore) SessionRelease(w http.ResponseWriter) {
63 c := rs.p.Get()
64 defer c.Close()
65
63 // if rs.values is empty, return directly 66 // if rs.values is empty, return directly
64 if len(rs.values) < 1 { 67 if len(rs.values) < 1 {
68 c.Do("DEL", rs.sid)
65 return 69 return
66 } 70 }
67 71
68 c := rs.p.Get()
69 defer c.Close()
70
71 b, err := encodeGob(rs.values) 72 b, err := encodeGob(rs.values)
72 if err != nil { 73 if err != nil {
73 return 74 return
...@@ -155,8 +156,15 @@ func (rp *RedisProvider) SessionRegenerate(oldsid, sid string) (SessionStore, er ...@@ -155,8 +156,15 @@ func (rp *RedisProvider) SessionRegenerate(oldsid, sid string) (SessionStore, er
155 c := rp.poollist.Get() 156 c := rp.poollist.Get()
156 defer c.Close() 157 defer c.Close()
157 158
159 if existed, _ := redis.Int(c.Do("EXISTS", oldsid)); existed == 0 {
160 // oldsid doesn't exists, set the new sid directly
161 // ignore error here, since if it return error
162 // the existed value will be 0
163 c.Do("SET", sid, "", "EX", rp.maxlifetime)
164 } else {
158 c.Do("RENAME", oldsid, sid) 165 c.Do("RENAME", oldsid, sid)
159 c.Do("EXPIRE", sid, rp.maxlifetime) 166 c.Do("EXPIRE", sid, rp.maxlifetime)
167 }
160 168
161 kvs, err := redis.String(c.Do("GET", sid)) 169 kvs, err := redis.String(c.Do("GET", sid))
162 var kv map[interface{}]interface{} 170 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!