pool

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: May 21, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package pool available index queue

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Avaliable

type Avaliable interface {
	Pop() int
	Put(int)
	Available() int
}

Avaliable avaliable interface

type Client

type Client struct {
	client.Client
	// contains filtered or unexported fields
}

Client pooled client

func (*Client) Close

func (c *Client) Close()

Close put the client to Connectors

type Connectors

type Connectors struct {

	//This function is called when automatic serialization is performed, and it can be modified to use a custom serialization method
	//进行自动序列化时将调用这个函数,修改它可以使用自定义的序列化方式
	EncodingFunc func(v interface{}) []byte
	// contains filtered or unexported fields
}

Connectors connection pool

连接池

func NewConnectors

func NewConnectors(cfg *conf.Config) *Connectors

NewConnectors initialize the connection pool using the configuration

@param cfg config

使用配置初始化连接池

func (*Connectors) Close

func (c *Connectors) Close()

Close close connectors

关闭连接池

func (*Connectors) GetClient

func (c *Connectors) GetClient() *Client

GetClient gets an error-free connection and, if there is an error, returns when the connected function is called

@return *Client

获取一个无错误的连接,如果有错误,将在调用连接的函数时返回

func (*Connectors) Info

func (c *Connectors) Info() string

Info returns connection pool status information

@return string

返回连接池状态信息

func (*Connectors) NewClient

func (c *Connectors) NewClient() (cli *Client, err error)

NewClient take a new connection in the connection pool and return an error if there is an error

@return client new client
@return error possible error, operation successfully returned nil

在连接池取一个新连接,如果出错将返回一个错误

func (*Connectors) SetNewClientRetryCount

func (c *Connectors) SetNewClientRetryCount(count byte)

SetNewClientRetryCount The number of times a connection is fetched from the fast connection pool, more than the retry number will enter the slow connection pool

@param count retry number

设置重试次数,大于这个次数就进入慢速池

func (*Connectors) Start

func (c *Connectors) Start() (err error)

Start start connectors

@return error,possible error, operation successfully returned nil

启动连接池

type Pool

type Pool struct {

	//new client
	New func() (*Client, error)
	// contains filtered or unexported fields
}

Pool pool block 连接池结构

func (*Pool) CheckClose

func (p *Pool) CheckClose()

CheckClose 检查是否可以关闭

func (*Pool) CheckHeath

func (p *Pool) CheckHeath()

CheckHeath check opened number

func (*Pool) Close

func (p *Pool) Close()

Close close pool

关闭连接池

func (*Pool) Get

func (p *Pool) Get() (client *Client)

Get get a pooled connection

@return *Client,client
@return error possible error, operation successfully returned nil

获取一个缓存的连接

func (*Pool) Set

func (p *Pool) Set(client *Client)

Set return the connection to the connection pool

@param client thd connection

返还一个连接到连接池

func (*Pool) Start

func (p *Pool) Start() (err error)

Start start the pool

@return error possible error, operation successfully returned nil

启动连接

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue queue for available index 可用连接的队列

func (*Queue) Available

func (q *Queue) Available() int

Available queue available size

func (*Queue) Empty

func (q *Queue) Empty() (re bool)

Empty check available index

@return bool

func (*Queue) Pop

func (q *Queue) Pop() (re int)

Pop get a index

@return int index

获取一个可以连接的位置

func (*Queue) Put

func (q *Queue) Put(i int)

Put return a index

@param i index
@return int pos

归还索引值

type Ring

type Ring struct {
	// contains filtered or unexported fields
}

Ring ring slice

func (*Ring) Available

func (r *Ring) Available() int

Available queue available size

func (*Ring) Pop

func (r *Ring) Pop() int

Pop get a index

@return int index

获取一个可以连接的位置

func (*Ring) Put

func (r *Ring) Put(v int)

Put return a index

@param i index
@return int pos

归还索引值

Jump to

Keyboard shortcuts

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