mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 08:30:54 +00:00
update sessionRelease
1. mysql fix last access time not update 2. mysql & redid Release when data is empty 3. add maxlifetime distinct Gclifetime
This commit is contained in:
parent
b766f65c26
commit
aa2fef0d36
@ -34,10 +34,3 @@ More info [beego.me](http://beego.me)
|
|||||||
|
|
||||||
beego is licensed under the Apache Licence, Version 2.0
|
beego is licensed under the Apache Licence, Version 2.0
|
||||||
(http://www.apache.org/licenses/LICENSE-2.0.html).
|
(http://www.apache.org/licenses/LICENSE-2.0.html).
|
||||||
|
|
||||||
|
|
||||||
## Use case
|
|
||||||
|
|
||||||
- Displaying API documentation: [gowalker](https://github.com/Unknwon/gowalker)
|
|
||||||
- seocms: [seocms](https://github.com/chinakr/seocms)
|
|
||||||
- CMS: [toropress](https://github.com/insionng/toropress)
|
|
||||||
|
@ -63,13 +63,13 @@ func (st *MysqlSessionStore) SessionID() string {
|
|||||||
|
|
||||||
func (st *MysqlSessionStore) SessionRelease(w http.ResponseWriter) {
|
func (st *MysqlSessionStore) SessionRelease(w http.ResponseWriter) {
|
||||||
defer st.c.Close()
|
defer st.c.Close()
|
||||||
if len(st.values) > 0 {
|
b, err := encodeGob(st.values)
|
||||||
b, err := encodeGob(st.values)
|
if err != nil {
|
||||||
if err != nil {
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
st.c.Exec("UPDATE session set `session_data`= ? where session_key=?", b, st.sid)
|
|
||||||
}
|
}
|
||||||
|
st.c.Exec("UPDATE session set `session_data`=?, `session_expiry`=? where session_key=?",
|
||||||
|
b, time.Now().Unix(), st.sid)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MysqlProvider struct {
|
type MysqlProvider struct {
|
||||||
@ -97,7 +97,8 @@ func (mp *MysqlProvider) SessionRead(sid string) (SessionStore, error) {
|
|||||||
var sessiondata []byte
|
var sessiondata []byte
|
||||||
err := row.Scan(&sessiondata)
|
err := row.Scan(&sessiondata)
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
c.Exec("insert into session(`session_key`,`session_data`,`session_expiry`) values(?,?,?)", sid, "", time.Now().Unix())
|
c.Exec("insert into session(`session_key`,`session_data`,`session_expiry`) values(?,?,?)",
|
||||||
|
sid, "", time.Now().Unix())
|
||||||
}
|
}
|
||||||
var kv map[interface{}]interface{}
|
var kv map[interface{}]interface{}
|
||||||
if len(sessiondata) == 0 {
|
if len(sessiondata) == 0 {
|
||||||
|
@ -61,14 +61,12 @@ func (rs *RedisSessionStore) SessionID() string {
|
|||||||
|
|
||||||
func (rs *RedisSessionStore) SessionRelease(w http.ResponseWriter) {
|
func (rs *RedisSessionStore) SessionRelease(w http.ResponseWriter) {
|
||||||
defer rs.c.Close()
|
defer rs.c.Close()
|
||||||
if len(rs.values) > 0 {
|
b, err := encodeGob(rs.values)
|
||||||
b, err := encodeGob(rs.values)
|
if err != nil {
|
||||||
if err != nil {
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
rs.c.Do("SET", rs.sid, string(b))
|
|
||||||
rs.c.Do("EXPIRE", rs.sid, rs.maxlifetime)
|
|
||||||
}
|
}
|
||||||
|
rs.c.Do("SET", rs.sid, string(b))
|
||||||
|
rs.c.Do("EXPIRE", rs.sid, rs.maxlifetime)
|
||||||
}
|
}
|
||||||
|
|
||||||
type RedisProvider struct {
|
type RedisProvider struct {
|
||||||
|
@ -52,6 +52,7 @@ type managerConfig struct {
|
|||||||
CookieName string `json:"cookieName"`
|
CookieName string `json:"cookieName"`
|
||||||
EnableSetCookie bool `json:"enableSetCookie,omitempty"`
|
EnableSetCookie bool `json:"enableSetCookie,omitempty"`
|
||||||
Gclifetime int64 `json:"gclifetime"`
|
Gclifetime int64 `json:"gclifetime"`
|
||||||
|
Maxlifetime int64 `json:"maxLifetime"`
|
||||||
Maxage int `json:"maxage"`
|
Maxage int `json:"maxage"`
|
||||||
Secure bool `json:"secure"`
|
Secure bool `json:"secure"`
|
||||||
SessionIDHashFunc string `json:"sessionIDHashFunc"`
|
SessionIDHashFunc string `json:"sessionIDHashFunc"`
|
||||||
@ -81,7 +82,11 @@ func NewManager(provideName, config string) (*Manager, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
provider.SessionInit(cf.Gclifetime, cf.ProviderConfig)
|
if cf.Maxlifetime == 0 {
|
||||||
|
cf.Maxlifetime = cf.Gclifetime
|
||||||
|
}
|
||||||
|
|
||||||
|
provider.SessionInit(cf.Maxlifetime, cf.ProviderConfig)
|
||||||
|
|
||||||
if cf.SessionIDHashFunc == "" {
|
if cf.SessionIDHashFunc == "" {
|
||||||
cf.SessionIDHashFunc = "sha1"
|
cf.SessionIDHashFunc = "sha1"
|
||||||
|
Loading…
Reference in New Issue
Block a user