Strengthens the session's function

This commit is contained in:
astaxie
2013-09-26 18:07:00 +08:00
parent 59a67720b4
commit 02c2e16253
5 changed files with 397 additions and 135 deletions

View File

@@ -35,6 +35,11 @@ func (rs *RedisSessionStore) Delete(key interface{}) error {
return err
}
func (rs *RedisSessionStore) Flush() error {
_, err := rs.c.Do("DEL", rs.sid)
return err
}
func (rs *RedisSessionStore) SessionID() string {
return rs.sid
}
@@ -99,6 +104,16 @@ func (rp *RedisProvider) SessionRead(sid string) (SessionStore, error) {
return rs, nil
}
func (rp *RedisProvider) SessionRegenerate(oldsid, sid string) (SessionStore, error) {
c := rp.connectInit()
if str, err := redis.String(c.Do("HGET", oldsid, oldsid)); err != nil || str == "" {
c.Do("HSET", oldsid, oldsid, rp.maxlifetime)
}
c.Do("RENAME", oldsid, sid)
rs := &RedisSessionStore{c: c, sid: sid}
return rs, nil
}
func (rp *RedisProvider) SessionDestroy(sid string) error {
c := rp.connectInit()
c.Do("DEL", sid)