pulled functions out of New()

This commit is contained in:
Jimmy Zelinskie 2013-06-25 23:08:54 -04:00
parent 2759dd6e2f
commit 7d99b0ea9e

View file

@ -21,7 +21,14 @@ func (d *driver) New(conf *config.Storage) (storage.Conn, error) {
pool: &redis.Pool{ pool: &redis.Pool{
MaxIdle: 3, MaxIdle: 3,
IdleTimeout: 240 * time.Second, IdleTimeout: 240 * time.Second,
Dial: func() (redis.Conn, error) { Dial: makeDialFunc(conf),
TestOnBorrow: testOnBorrow,
},
}, nil
}
func makeDialFunc(conf *config.Storage) func() (redis.Conn, error) {
return func() (redis.Conn, error) {
var ( var (
conn redis.Conn conn redis.Conn
err error err error
@ -45,13 +52,12 @@ func (d *driver) New(conf *config.Storage) (storage.Conn, error) {
return nil, err return nil, err
} }
return conn, nil return conn, nil
}, }
TestOnBorrow: func(c redis.Conn, t time.Time) error { }
func testOnBorrow(c redis.Conn, t time.Time) error {
_, err := c.Do("PING") _, err := c.Do("PING")
return err return err
},
},
}, nil
} }
type Conn struct { type Conn struct {