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 }
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) }
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 }