示例#1
0
文件: pool.go 项目: lucmichalski/fae
func New(cf *config.ConfigMemcache) *ClientPool {
	this := new(ClientPool)
	this.conf = cf
	this.clients = make(map[string]*Client)
	for _, pool := range cf.Pools() {
		this.clients[pool] = newClient(cf)
	}
	return this
}
示例#2
0
func getClient(hash string, servers ...string) *Client {
	var cf = config.ConfigMemcache{HashStrategy: hash}
	cf.Servers = make(map[string]*config.ConfigMemcacheServer)
	for _, server := range servers {
		svr := new(config.ConfigMemcacheServer)
		p := strings.Split(server, ":")
		svr.Host, svr.Port = p[0], p[1]
		cf.Servers[svr.Address()] = svr
	}

	return newClient(&cf)
}
示例#3
0
func newClient(cf *config.ConfigMemcache) (this *Client) {
	this = new(Client)
	this.conf = cf
	this.breakers = make(map[net.Addr]*breaker.Consecutive)
	this.throttleConns = make(map[net.Addr]chan interface{})

	switch cf.HashStrategy {
	case ConstistentHashStrategy:
		this.selector = new(ConsistentServerSelector)

	default:
		this.selector = new(StandardServerSelector)
	}

	if err := this.selector.SetServers(cf.ServerList()...); err != nil {
		panic(err)
	}

	return
}