This topic created in 4379 days ago, the information mentioned may be changed or developed.
Supplement 1 · May 21, 2014
已解决。
原因已查到,不是redis本身的问题,是在连接redis服务器的时候net.Dial() 偶然会block,
同一局域网内,原因未知。
版本:go version go1.2.1 freebsd/amd64
目前解决办法:
往连接池补充的时候使用双连接,同时加上超时重试,通过一晚上测试,工作良好。
大致代码:
// 双连接channel
chanClient := make(chan *redis.Client,2)
var newClient = func(channel chan *redis.Client){
c,err := redis.Dial(....)
if err != nil {
return
}
channel<-c
}
go newClient(chanClient)
go newClient(chanClient) //连接2次
select {
case client:= <- chanClient :
// 成功连接,加入连接池
// 代码,略
case <-time.After(...一个短的超时...)
// 双连接都不行,重试几次看看
}
go func(channel *redis.Client,n int){
// 因为之前连接两次,
// 1. 收集剩下的连接结果,有成功的加入连接池
// 2. 一个较大的超时时间,过后就认为所有连接失败,忽略它们
}(chanClient,waitNclients)
6 replies • 2014-05-21 13:08:33 +08:00
 |
|
3
se77en May 20, 2014
github 上选 star 最多的
|