mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
实例化Redis新增dialOpts参数以支持redis更多拨号设置 (#475)
* 实例化Redis新dialOpts参数以支持redis更多拨号设置 * debug * gofmt file * remove go.mod empty line Co-authored-by: Jerry <prc.tzy@gmail.com>
This commit is contained in:
7
cache/redis.go
vendored
7
cache/redis.go
vendored
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user