-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathredis.go
51 lines (42 loc) · 1.38 KB
/
redis.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 redis
import (
`github.com/go-redis/redis/v8`
`github.com/pangum/pangu`
)
func newRedis(config *pangu.Config) (client *Client, err error) {
_panguConfig := new(panguConfig)
if err = config.Load(_panguConfig); nil != err {
return
}
redisConfig := _panguConfig.Redis
// 加载默认连接
optionsCache := make(map[string]*redis.Options)
serializerCache := make(map[string]serializer)
if `` != redisConfig.Addr {
_defaultOptions := &redis.Options{
Addr: redisConfig.Addr,
Username: redisConfig.Options.Username,
Password: redisConfig.Options.Password,
DB: redisConfig.Options.DB,
}
optionsCache[defaultLabel] = _defaultOptions
serializerCache[defaultLabel] = redisConfig.Options.Serializer
}
// 加载带标签的服务器
for _, _server := range redisConfig.Servers {
serverOptions := &redis.Options{
Addr: mustString(_server.Addr, redisConfig.Addr),
Username: mustString(_server.Options.Username, redisConfig.Options.Username),
Password: mustString(_server.Options.Password, redisConfig.Options.Password),
DB: mustInt(_server.Options.DB, redisConfig.Options.DB),
}
optionsCache[_server.Label] = serverOptions
serializerCache[_server.Label] = _server.Options.Serializer
}
client = &Client{
clientCache: make(map[string]*redis.Client),
optionsCache: optionsCache,
serializerCache: serializerCache,
}
return
}