pool

package
v0.0.0-...-3335154 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	//ErrClosed 连接池已经关闭Error
	ErrClosed        = errors.New("pool is closed")
	ErrRegisterPool  = errors.New("register pool error")
	ErrReleasePool   = errors.New("release pool error")
	ErrGetConnection = errors.New("get connection error")
	ErrPutConnection = errors.New("put connection error")
)

Functions

func GetClient

func GetClient(poolName string) (c interface{}, err error)

func IsRegister

func IsRegister(poolName string) (ok bool)

func PutClient

func PutClient(poolName string, c interface{}) (err error)

func RegisterClickPool

func RegisterClickPool(poolName string, url string, force bool, params ...int) (err error)

func RegisterMgoPool

func RegisterMgoPool(poolName string, url string, force bool, params ...int) (err error)

func RegisterPool

func RegisterPool(poolName string, p Pooler, force bool, params ...int) (err error)

func ReleaseAll

func ReleaseAll()

func ReleasePool

func ReleasePool(poolName string)

Types

type ClickConn

type ClickConn struct {
	Address string
}

func (*ClickConn) Close

func (c *ClickConn) Close(v interface{}) (err error)

func (*ClickConn) Factory

func (c *ClickConn) Factory() (v interface{}, err error)

func (*ClickConn) Ping

func (c *ClickConn) Ping(v interface{}) (err error)

type Config

type Config struct {
	//连接池中拥有的最小连接数
	InitialCap int
	//连接池中拥有的最大的连接数
	MaxCap int
	//生成连接的方法
	Factory func() (interface{}, error)
	//关闭连接的方法
	Close func(interface{}) error
	//检查连接是否有效的方法
	Ping func(interface{}) error
	//连接最大空闲时间,超过该事件则将失效
	IdleTimeout time.Duration
}

Config 连接池相关配置

type DriverType

type DriverType int

type MgoConn

type MgoConn struct {
	Address string
}

func (*MgoConn) Close

func (c *MgoConn) Close(v interface{}) (err error)

func (*MgoConn) Factory

func (c *MgoConn) Factory() (v interface{}, err error)

func (*MgoConn) Ping

func (c *MgoConn) Ping(v interface{}) (err error)

type Pool

type Pool interface {
	Get() (interface{}, error)

	Put(interface{}) error

	Close(interface{}) error

	Release()

	Len() int
}

Pool 基本方法

func NewChannelPool

func NewChannelPool(poolConfig *Config) (Pool, error)

NewChannelPool 初始化连接

type Pooler

type Pooler interface {
	Factory() (interface{}, error)
	Ping(interface{}) error
	Close(interface{}) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL