mongo-go-driver

// NewPool creates a new pool that will hold size number of idle connections
// and will create a max of capacity connections. It will use the provided
// options.
func NewPool(addr address.Address, size, capacity uint64, opts ...Option) (Pool, error) {
    if size > capacity {
        return nil, ErrSizeLargerThanCapacity
    }
    p := &pool{
        address:    addr,
        conns:      make(chan *pooledConnection, size),
        generation: 0,
        sem:        semaphore.NewWeighted(int64(capacity)),
        connected:  disconnected,
        capacity:   capacity,
        inflight:   make(map[uint64]*pooledConnection),
        opts:       opts,
    }
    return p, nil
}

这个https://github.com/mongodb/mongo-go-driver/blob/master/x/network/connection/pool.go 这个是怎么用的,官方驱动现在稳定了吗?

已邀请:

m12

赞同来自:

官方驱动的连接池怎么写,小白不懂这个。

kevin - 杭州云柚科技

赞同来自:

这不是很清楚么,第一个是地址,第二个是的最小保持连接数,第三个是上限连接数,第四个是选项

要回复问题请先登录注册