Documentation
¶
Index ¶
Constants ¶
View Source
const ( //连接池状态:创建 PoolInit = 0 //连接池状态:运行 PoolStart = 1 //连接池状态:关闭 PoolStop = -1 //连接池状态:重启 PoolReStart = 2 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IClient ¶
type IClient interface {
//打开连接
//
// 返回,error。如果连接到服务器时出错,就返回错误信息,否则返回nil
Start() error
//关闭连接
//
// 返回,error。如果关闭连接时出错,就返回错误信息,否则返回nil
Close() error
//是否打开
//
// 返回,bool。如果已连接到服务器,就返回true。
IsOpen() bool
//检查连接状态
//
// 返回,bool。如果无法访问服务器,就返回false。
Ping() bool
}
连接接口
连接池内的连接结构只要实现这个接口就可以嵌入池内使用
type Pool ¶
type Pool struct {
//create new Closed
NewClient func() IClient
//状态
Status int
//config
//获取连接超时时间,单位为秒。默认值: 5
GetClientTimeout int
//最大连接池个数。默认值: 20
MaxPoolSize int
//最小连接池数。默认值: 5
MinPoolSize int
//当连接池中的连接耗尽的时候一次同时获取的连接数。默认值: 5
AcquireIncrement int
//最大等待数目,当连接池满后,新建连接将等待池中连接释放后才可以继续,本值限制最大等待的数量,超过本值后将抛出异常。默认值: 1000
MaxWaitSize int
//连接池内缓存的连接状态检查时间隔,单位为秒。默认值: 5
HealthSecond int
//连接空闲时间,超过这个时间可能会被回收,单位为秒。默认值:60
IdleTime int
// contains filtered or unexported fields
}
连接池结构
func (*Pool) Get ¶
func (p *Pool) Get() (client *PooledClient, err error)
在连接池取一个新连接
返回 client,一个新的连接 返回 err,可能的错误,操作成功返回 nil
type PooledClient ¶
type PooledClient struct {
//value
Client IClient
// contains filtered or unexported fields
}
缓存的连接
内部使用
type Slice ¶
type Slice struct {
// contains filtered or unexported fields
}
使用slice实现的池
func (*Slice) Get ¶
func (s *Slice) Get() (*PooledClient, error)
获取一个连接
返回 *PooledClient 缓存的连接 返回 error 可能的错误
Click to show internal directories.
Click to hide internal directories.