Skip to content

Commit

Permalink
实例化Redis新增dialOpts参数以支持redis更多拨号设置 (#475)
Browse files Browse the repository at this point in the history
* 实例化Redis新dialOpts参数以支持redis更多拨号设置

* debug

* gofmt file

* remove go.mod empty line

Co-authored-by: Jerry <[email protected]>
  • Loading branch information
JerryTam and jt-git authored Sep 9, 2021
1 parent 96c1f98 commit d3d91b8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ type RedisOpts struct {
}

// NewRedis 实例化
func NewRedis(opts *RedisOpts) *Redis {
func NewRedis(opts *RedisOpts, dialOpts ...redis.DialOption) *Redis {
pool := &redis.Pool{
MaxActive: opts.MaxActive,
MaxIdle: opts.MaxIdle,
IdleTimeout: time.Second * time.Duration(opts.IdleTimeout),
Dial: func() (redis.Conn, error) {
return redis.Dial("tcp", opts.Host,
dialOpts = append(dialOpts, []redis.DialOption{
redis.DialDatabase(opts.Database),
redis.DialPassword(opts.Password),
)
}...)
return redis.Dial("tcp", opts.Host, dialOpts...)
},
TestOnBorrow: func(conn redis.Conn, t time.Time) error {
if time.Since(t) < time.Minute {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ require (
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/h2non/gock.v1 v1.0.15
)
)

0 comments on commit d3d91b8

Please sign in to comment.