فهرست منبع

实例化Redis新增dialOpts参数以支持redis更多拨号设置 (#475)

* 实例化Redis新dialOpts参数以支持redis更多拨号设置

* debug

* gofmt file

* remove go.mod empty line

Co-authored-by: Jerry <prc.tzy@gmail.com>
JerryTam 4 سال پیش
والد
کامیت
d3d91b8d29
2فایلهای تغییر یافته به همراه5 افزوده شده و 4 حذف شده
  1. 4 3
      cache/redis.go
  2. 1 1
      go.mod

+ 4 - 3
cache/redis.go

@@ -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 {

+ 1 - 1
go.mod

@@ -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
-)
+)