mirror of
https://github.com/kataras/iris.git
synced 2026-03-06 08:25:59 +00:00
remove MaxAgeSeconds from redis sessiondb - now it derives from the sessions configuration automatically. Add option to use an existing BoltDB connection on boltdb sessiondb.
TODO: leveldb sessiondb Former-commit-id: 8cb781bf089ab7b9a09dccc633454db9c6077610
This commit is contained in:
@@ -44,15 +44,21 @@ func (r *Service) CloseConnection() error {
|
||||
|
||||
// Set sets a key-value to the redis store.
|
||||
// The expiration is setted by the MaxAgeSeconds.
|
||||
func (r *Service) Set(key string, value interface{}) error {
|
||||
func (r *Service) Set(key string, value interface{}, secondsLifetime int) (err error) {
|
||||
c := r.pool.Get()
|
||||
defer c.Close()
|
||||
if c.Err() != nil {
|
||||
return c.Err()
|
||||
}
|
||||
|
||||
_, err := c.Do("SETEX", r.Config.Prefix+key, r.Config.MaxAgeSeconds, value)
|
||||
return err
|
||||
// if has expiration, then use the "EX" to delete the key automatically.
|
||||
if secondsLifetime > 0 {
|
||||
_, err = c.Do("SETEX", r.Config.Prefix+key, secondsLifetime, value)
|
||||
} else {
|
||||
_, err = c.Do("SET", r.Config.Prefix+key, value)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Get returns value, err by its key
|
||||
@@ -164,10 +170,6 @@ func (r *Service) Connect() {
|
||||
c.Addr = DefaultRedisAddr
|
||||
}
|
||||
|
||||
if c.MaxAgeSeconds <= 0 {
|
||||
c.MaxAgeSeconds = DefaultRedisMaxAgeSeconds
|
||||
}
|
||||
|
||||
pool := &redis.Pool{IdleTimeout: DefaultRedisIdleTimeout, MaxIdle: c.MaxIdle, MaxActive: c.MaxActive}
|
||||
pool.TestOnBorrow = func(c redis.Conn, t time.Time) error {
|
||||
_, err := c.Do("PING")
|
||||
|
||||
Reference in New Issue
Block a user