示例#1
0
// BuildSession factory
func BuildSession(cfg Config) (fac SessionFactory, err error) {
	pool := &redis.Pool{
		MaxIdle:     3,
		IdleTimeout: 240 * time.Second,
		Dial: func() (redis.Conn, error) {
			return redis.Dial("tcp", cfg["RedisAddr"])
		},
		TestOnBorrow: func(c redis.Conn, t time.Time) error {
			_, err := c.Do("PING")
			return err
		},
	}
	store, err := redistore.NewRediStoreWithPool(pool, []byte(cfg["SessSecret"]))
	if err != nil {
		return
	}

	fac = &sf{store, cfg["SessName"]}
	return
}
示例#2
0
// NewRediStoreWithPool instantiates a RediStore with a *redis.Pool passed in.
func NewRediStoreWithPool(pool *redis.Pool, keyPairs []byte) *redisStore {
	store, _ := redistore.NewRediStoreWithPool(pool, keyPairs)
	return &redisStore{store}
}