From d3d91b8d297fd7c9a593757ea223549aadd0a57b Mon Sep 17 00:00:00 2001 From: JerryTam Date: Thu, 9 Sep 2021 12:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E5=8C=96Redis=E6=96=B0?= =?UTF-8?q?=E5=A2=9EdialOpts=E5=8F=82=E6=95=B0=E4=BB=A5=E6=94=AF=E6=8C=81r?= =?UTF-8?q?edis=E6=9B=B4=E5=A4=9A=E6=8B=A8=E5=8F=B7=E8=AE=BE=E7=BD=AE=20(#?= =?UTF-8?q?475)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 实例化Redis新dialOpts参数以支持redis更多拨号设置 * debug * gofmt file * remove go.mod empty line Co-authored-by: Jerry --- cache/redis.go | 7 ++++--- go.mod | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) 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