a5029cc4 by astaxie

Merge pull request #370 from slene/master

fix set maxlifetime, close conn
2 parents 495033b9 d48b7e01
...@@ -15,10 +15,11 @@ var MAX_POOL_SIZE = 100 ...@@ -15,10 +15,11 @@ var MAX_POOL_SIZE = 100
15 var redisPool chan redis.Conn 15 var redisPool chan redis.Conn
16 16
17 type RedisSessionStore struct { 17 type RedisSessionStore struct {
18 c redis.Conn 18 c redis.Conn
19 sid string 19 sid string
20 lock sync.RWMutex 20 lock sync.RWMutex
21 values map[interface{}]interface{} 21 values map[interface{}]interface{}
22 maxlifetime int64
22 } 23 }
23 24
24 func (rs *RedisSessionStore) Set(key, value interface{}) error { 25 func (rs *RedisSessionStore) Set(key, value interface{}) error {
...@@ -65,6 +66,7 @@ func (rs *RedisSessionStore) SessionRelease() { ...@@ -65,6 +66,7 @@ func (rs *RedisSessionStore) SessionRelease() {
65 return 66 return
66 } 67 }
67 rs.c.Do("SET", rs.sid, string(b)) 68 rs.c.Do("SET", rs.sid, string(b))
69 rs.c.Do("EXPIRE", rs.sid, rs.maxlifetime)
68 } 70 }
69 } 71 }
70 72
...@@ -129,12 +131,13 @@ func (rp *RedisProvider) SessionRead(sid string) (SessionStore, error) { ...@@ -129,12 +131,13 @@ func (rp *RedisProvider) SessionRead(sid string) (SessionStore, error) {
129 return nil, err 131 return nil, err
130 } 132 }
131 } 133 }
132 rs := &RedisSessionStore{c: c, sid: sid, values: kv} 134 rs := &RedisSessionStore{c: c, sid: sid, values: kv, maxlifetime: rp.maxlifetime}
133 return rs, nil 135 return rs, nil
134 } 136 }
135 137
136 func (rp *RedisProvider) SessionExist(sid string) bool { 138 func (rp *RedisProvider) SessionExist(sid string) bool {
137 c := rp.poollist.Get() 139 c := rp.poollist.Get()
140 defer c.Close()
138 if existed, err := redis.Int(c.Do("EXISTS", sid)); err != nil || existed == 0 { 141 if existed, err := redis.Int(c.Do("EXISTS", sid)); err != nil || existed == 0 {
139 return false 142 return false
140 } else { 143 } else {
...@@ -159,12 +162,13 @@ func (rp *RedisProvider) SessionRegenerate(oldsid, sid string) (SessionStore, er ...@@ -159,12 +162,13 @@ func (rp *RedisProvider) SessionRegenerate(oldsid, sid string) (SessionStore, er
159 return nil, err 162 return nil, err
160 } 163 }
161 } 164 }
162 rs := &RedisSessionStore{c: c, sid: sid, values: kv} 165 rs := &RedisSessionStore{c: c, sid: sid, values: kv, maxlifetime: rp.maxlifetime}
163 return rs, nil 166 return rs, nil
164 } 167 }
165 168
166 func (rp *RedisProvider) SessionDestroy(sid string) error { 169 func (rp *RedisProvider) SessionDestroy(sid string) error {
167 c := rp.poollist.Get() 170 c := rp.poollist.Get()
171 defer c.Close()
168 c.Do("DEL", sid) 172 c.Do("DEL", sid)
169 return nil 173 return nil
170 } 174 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!