diff --git a/cache/redis.go b/cache/redis.go index f685e6a..6fdf643 100644 --- a/cache/redis.go +++ b/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 { diff --git a/go.mod b/go.mod index cce929f..c091722 100644 --- a/go.mod +++ b/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 -) +) \ No newline at end of file