2017-11-09 07:40:55 +00:00
|
|
|
package redis_pool
|
2017-09-01 04:10:35 +00:00
|
|
|
|
|
|
|
import (
|
2017-11-09 07:40:55 +00:00
|
|
|
"fmt"
|
2017-09-01 04:10:35 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/garyburd/redigo/redis"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PoolHandlers struct {
|
|
|
|
// Maximum number of connections allocated by the pool at a given time.
|
|
|
|
// When zero, there is no limit on the number of connections in the pool.
|
2017-11-09 07:40:55 +00:00
|
|
|
MaxCapacity int
|
|
|
|
|
|
|
|
// Maximum number of idle connections in the pool.
|
|
|
|
MaxIdle int
|
2017-09-01 04:10:35 +00:00
|
|
|
|
|
|
|
// Close connections after remaining idle for this duration. If the value
|
|
|
|
// is zero, then idle connections are not closed. Applications should set
|
|
|
|
// the timeout to a value less than the server's timeout.
|
|
|
|
IdleTimeout time.Duration
|
|
|
|
|
|
|
|
// If Wait is true and the pool is at the MaxActive limit, then Get() waits
|
|
|
|
// for a connection to be returned to the pool before returning.
|
|
|
|
Wait bool
|
|
|
|
}
|
|
|
|
|
2017-11-09 07:40:55 +00:00
|
|
|
func (ph *PoolHandlers) Dial() (redis.Conn, error) {
|
|
|
|
return nil, fmt.Errorf("Redis Pool: Dial method is not implemented")
|
2017-09-01 04:10:35 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 07:40:55 +00:00
|
|
|
func (ph *PoolHandlers) TestOnBorrow(c redis.Conn, t time.Time) error {
|
2017-09-01 04:10:35 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-09 07:40:55 +00:00
|
|
|
func (ph *PoolHandlers) GetMaxCapacity() int {
|
|
|
|
return ph.MaxCapacity
|
2017-09-01 04:10:35 +00:00
|
|
|
}
|
2017-11-09 07:40:55 +00:00
|
|
|
func (ph *PoolHandlers) GetMaxIdle() int {
|
|
|
|
return ph.MaxIdle
|
2017-09-01 04:10:35 +00:00
|
|
|
}
|
2017-11-09 07:40:55 +00:00
|
|
|
func (ph *PoolHandlers) GetIdleTimeout() time.Duration {
|
|
|
|
return ph.IdleTimeout
|
|
|
|
}
|
|
|
|
func (ph *PoolHandlers) IsWait() bool {
|
|
|
|
return ph.Wait
|
2017-09-01 04:10:35 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 07:40:55 +00:00
|
|
|
func (ph *PoolHandlers) Validate() {
|
|
|
|
if ph.MaxIdle <= 0 {
|
|
|
|
ph.MaxIdle = DefaultMaxIdle
|
|
|
|
}
|
|
|
|
if ph.MaxActive <= 0 {
|
|
|
|
ph.MaxActive = DefaultMaxActive
|
|
|
|
}
|
|
|
|
if ph.IdleTimeout <= 0 {
|
|
|
|
ph.IdleTimeout = DefaultIdleTimeout
|
|
|
|
}
|
2017-09-01 04:10:35 +00:00
|
|
|
}
|