1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-10 10:50:17 +00:00

fix #1473,Only update redis session if it already exist

This commit is contained in:
ysqi
2016-01-07 20:42:26 +08:00
parent 434544060a
commit 58e2a7c099
2 changed files with 70 additions and 3 deletions

View File

@ -98,15 +98,18 @@ func (rs *SessionStore) SessionID() string {
// SessionRelease save session values to redis
func (rs *SessionStore) SessionRelease(w http.ResponseWriter) {
c := rs.p.Get()
defer c.Close()
b, err := session.EncodeGob(rs.values)
if err != nil {
return
}
c.Do("SETEX", rs.sid, rs.maxlifetime, string(b))
c := rs.p.Get()
defer c.Close()
// Update session value if exists or error.
if existed, err := redis.Bool(c.Do("EXISTS", rs.sid)); existed || err != nil {
c.Do("SETEX", rs.sid, rs.maxlifetime, string(b))
}
}
// Provider redis session provider