|
@@ -23,16 +23,17 @@ type RedisOpts struct {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// NewRedis 实例化
|
|
// NewRedis 实例化
|
|
|
-func NewRedis(opts *RedisOpts) *Redis {
|
|
|
|
|
|
|
+func NewRedis(opts *RedisOpts, dialOpts ...redis.DialOption) *Redis {
|
|
|
pool := &redis.Pool{
|
|
pool := &redis.Pool{
|
|
|
MaxActive: opts.MaxActive,
|
|
MaxActive: opts.MaxActive,
|
|
|
MaxIdle: opts.MaxIdle,
|
|
MaxIdle: opts.MaxIdle,
|
|
|
IdleTimeout: time.Second * time.Duration(opts.IdleTimeout),
|
|
IdleTimeout: time.Second * time.Duration(opts.IdleTimeout),
|
|
|
Dial: func() (redis.Conn, error) {
|
|
Dial: func() (redis.Conn, error) {
|
|
|
- return redis.Dial("tcp", opts.Host,
|
|
|
|
|
|
|
+ dialOpts = append(dialOpts, []redis.DialOption{
|
|
|
redis.DialDatabase(opts.Database),
|
|
redis.DialDatabase(opts.Database),
|
|
|
redis.DialPassword(opts.Password),
|
|
redis.DialPassword(opts.Password),
|
|
|
- )
|
|
|
|
|
|
|
+ }...)
|
|
|
|
|
+ return redis.Dial("tcp", opts.Host, dialOpts...)
|
|
|
},
|
|
},
|
|
|
TestOnBorrow: func(conn redis.Conn, t time.Time) error {
|
|
TestOnBorrow: func(conn redis.Conn, t time.Time) error {
|
|
|
if time.Since(t) < time.Minute {
|
|
if time.Since(t) < time.Minute {
|