-
Notifications
You must be signed in to change notification settings - Fork 11
/
options.go
51 lines (43 loc) · 1.12 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package redigo
import (
"github.com/gomodule/redigo/redis"
"time"
)
// PoolOption 连接池配置函数
type PoolOption func(pool *redis.Pool)
// Wait 连接池枯竭是是否阻塞等待
func Wait(value bool) PoolOption {
return func(pool *redis.Pool) {
pool.Wait = value
}
}
// MaxIdle 最多允许空闲的连接数
func MaxIdle(value int) PoolOption {
return func(pool *redis.Pool) {
pool.MaxIdle = value
}
}
// MaxActive 最多允许的连接数, 0 则无限制
func MaxActive(value int) PoolOption {
return func(pool *redis.Pool) {
pool.MaxActive = value
}
}
// IdleTimeout 最大空闲时长, 超过后关闭连接
func IdleTimeout(value time.Duration) PoolOption {
return func(pool *redis.Pool) {
pool.IdleTimeout = value
}
}
// MaxConnLifetime 连接生命周期, 超过后关闭连接
func MaxConnLifetime(value time.Duration) PoolOption {
return func(pool *redis.Pool) {
pool.MaxConnLifetime = value
}
}
// TestOnBorrow 健康检查, 检测连接是否可用
func TestOnBorrow(value func(c redis.Conn, t time.Time) (err error)) PoolOption {
return func(pool *redis.Pool) {
pool.TestOnBorrow = value
}
}