// return a ConnectionPool instance, and for each server initializes a connection pool func New(config *config.Config) (Pool, error) { if len(config.Servers) == 0 { return nil, errors.New("Memcached : Memcached Servers must not empty") } pool := &ConnectionPool{ pools: make([]chan *common.Conn, 0, len(config.Servers)), config: config, factory: factory.NewConnectionFactory(config), consistent: selector.NewConsistent(config), } for i := 0; i < len(pool.config.Servers); i++ { pool.pools = append(pool.pools, make(chan *common.Conn, pool.config.InitConns)) for j := 0; j < int(pool.config.InitConns / 2 + 1); j++ { conn, err := pool.factory.NewTcpConnect(pool.config.Servers[i], i) if err != nil { return nil, err } else { pool.pools[i] <- conn } } pool.consistent.Add(pool.config.Servers[i]) } pool.consistent.RefreshTicker() return pool, nil }
func NewConsistent(c *config.Config) *Consistent { return &Consistent{ config: c, circle: list.New(), numberOfReplicas: c.NumberOfReplicas, factory: factory.NewConnectionFactory(c), nodesStatus: make([]bool, len(c.Servers)), } }