Skip to content

Commit

Permalink
Merge pull request #14 from taitai42/master
Browse files Browse the repository at this point in the history
add redis pool support
  • Loading branch information
ipfans committed Jul 17, 2017
2 parents 1228927 + 8b8ba1c commit 53b0785
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion redis_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package session

import (
"github.com/boj/redistore"
"github.com/garyburd/redigo/redis"
"github.com/gorilla/sessions"
)

Expand Down Expand Up @@ -30,6 +31,24 @@ func NewRedisStore(size int, network, address, password string, keyPairs ...[]by
return &redisStore{store}, nil
}

// pool: redis pool connections
// Keys are defined in pairs to allow key rotation, but the common case is to set a single
// authentication key and optionally an encryption key.
//
// The first key in a pair is used for authentication and the second for encryption. The
// encryption key can be set to nil or omitted in the last pair, but the authentication key
// is required in all pairs.
//
// It is recommended to use an authentication key with 32 or 64 bytes. The encryption key,
// if set, must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256 modes.
func NewRedisStoreWithPool(pool *redis.Pool, keyPairs ...[]byte) (RedisStore, error) {
store, err := redistore.NewRediStoreWithPool(pool, keyPairs...)
if err != nil {
return nil, err
}
return &redisStore{store}, nil
}

type redisStore struct {
*redistore.RediStore
}
Expand All @@ -56,4 +75,4 @@ func (c *redisStore) Options(options Options) {
// use this function to change `MaxAge` value.
func (c *redisStore) MaxAge(age int) {
c.RediStore.SetMaxAge(age)
}
}

0 comments on commit 53b0785

Please sign in to comment.