Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ type Client struct {
// NewClient creates a new client connecting to the redis host, and using the given name as key prefix.
// Addr can be a single host:port pair, or a comma separated list of host:port,host:port...
// In the case of multiple hosts we create a multi-pool and select connections at random
func NewClient(addr, name string, authPass *string) *Client {
func NewClient(addr, name string, authPass *string, options ...redis.DialOption) *Client {
addrs := strings.Split(addr, ",")
var pool ConnPool
if len(addrs) == 1 {
pool = NewSingleHostPool(addrs[0], authPass)
pool = NewSingleHostPool(addrs[0], authPass, options...)
} else {
pool = NewMultiHostPool(addrs, authPass)
pool = NewMultiHostPool(addrs, authPass, options...)
}
ret := &Client{
Pool: pool,
Expand Down
14 changes: 8 additions & 6 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ type SingleHostPool struct {
// s.Pool.Close()
//}

func NewSingleHostPool(host string, authPass *string) *SingleHostPool {
func NewSingleHostPool(host string, authPass *string, options ...redis.DialOption) *SingleHostPool {
ret := &redis.Pool{
Dial: dialFuncWrapper(host, authPass),
Dial: dialFuncWrapper(host, authPass, options...),
TestOnBorrow: testOnBorrow,
MaxIdle: maxConns,
}
Expand All @@ -38,6 +38,7 @@ type MultiHostPool struct {
pools map[string]*redis.Pool
hosts []string
authPass *string
options []redis.DialOption
}

func (p *MultiHostPool) Close() (err error) {
Expand All @@ -57,11 +58,12 @@ func (p *MultiHostPool) Close() (err error) {
return
}

func NewMultiHostPool(hosts []string, authPass *string) *MultiHostPool {
func NewMultiHostPool(hosts []string, authPass *string, options ...redis.DialOption) *MultiHostPool {
return &MultiHostPool{
pools: make(map[string]*redis.Pool, len(hosts)),
hosts: hosts,
authPass: authPass,
options: options,
}
}

Expand All @@ -74,7 +76,7 @@ func (p *MultiHostPool) Get() redis.Conn {

if !found {
pool = &redis.Pool{
Dial: dialFuncWrapper(host, p.authPass),
Dial: dialFuncWrapper(host, p.authPass, p.options...),
TestOnBorrow: testOnBorrow,
MaxIdle: maxConns,
}
Expand All @@ -84,9 +86,9 @@ func (p *MultiHostPool) Get() redis.Conn {
return pool.Get()
}

func dialFuncWrapper(host string, authPass *string) func() (redis.Conn, error) {
func dialFuncWrapper(host string, authPass *string, options ...redis.DialOption) func() (redis.Conn, error) {
return func() (redis.Conn, error) {
conn, err := redis.Dial("tcp", host)
conn, err := redis.Dial("tcp", host, options...)
if err != nil {
return conn, err
}
Expand Down