1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-01 00:00:54 +00:00

#369 set maxlifetime, close conn

This commit is contained in:
slene 2013-12-14 23:29:17 +08:00
parent 495033b977
commit d48b7e0101

View File

@ -15,10 +15,11 @@ var MAX_POOL_SIZE = 100
var redisPool chan redis.Conn
type RedisSessionStore struct {
c redis.Conn
sid string
lock sync.RWMutex
values map[interface{}]interface{}
c redis.Conn
sid string
lock sync.RWMutex
values map[interface{}]interface{}
maxlifetime int64
}
func (rs *RedisSessionStore) Set(key, value interface{}) error {
@ -65,6 +66,7 @@ func (rs *RedisSessionStore) SessionRelease() {
return
}
rs.c.Do("SET", rs.sid, string(b))
rs.c.Do("EXPIRE", rs.sid, rs.maxlifetime)
}
}
@ -129,12 +131,13 @@ func (rp *RedisProvider) SessionRead(sid string) (SessionStore, error) {
return nil, err
}
}
rs := &RedisSessionStore{c: c, sid: sid, values: kv}
rs := &RedisSessionStore{c: c, sid: sid, values: kv, maxlifetime: rp.maxlifetime}
return rs, nil
}
func (rp *RedisProvider) SessionExist(sid string) bool {
c := rp.poollist.Get()
defer c.Close()
if existed, err := redis.Int(c.Do("EXISTS", sid)); err != nil || existed == 0 {
return false
} else {
@ -159,12 +162,13 @@ func (rp *RedisProvider) SessionRegenerate(oldsid, sid string) (SessionStore, er
return nil, err
}
}
rs := &RedisSessionStore{c: c, sid: sid, values: kv}
rs := &RedisSessionStore{c: c, sid: sid, values: kv, maxlifetime: rp.maxlifetime}
return rs, nil
}
func (rp *RedisProvider) SessionDestroy(sid string) error {
c := rp.poollist.Get()
defer c.Close()
c.Do("DEL", sid)
return nil
}