Documentation ¶
Index ¶
- Variables
- func GetCallInArgs(funcValue reflect.Value, funcArgs []string, inStart int) ([]reflect.Value, error)
- func GetStrMd5(s string) string
- func GetStrSha1(data string) string
- func GoValuesToYJsonSlice(values []reflect.Value) ([]string, error)
- func GoVarToYJson(v interface{}) (string, error)
- func GoVarsToYJsonSlice(args ...interface{}) ([]string, error)
- func Max(a, b int) int
- func Min(a, b int) int
- type ConnInterface
- type ConnPool
- func (p *ConnPool) Close()
- func (p *ConnPool) CloseConn(conn interface{})
- func (p *ConnPool) DecodeId(id string) (n int, t int64)
- func (p *ConnPool) GenId(randomNum int) string
- func (p *ConnPool) Get() (interface{}, error)
- func (p *ConnPool) IsConnTimeout(conn interface{}) bool
- func (p *ConnPool) Lock()
- func (p *ConnPool) NewConn() (interface{}, error)
- func (p *ConnPool) Put(conn interface{}, isBadConn bool)
- func (p *ConnPool) UnLock()
- func (p *ConnPool) UpdateConnTime(conn interface{})
- type ConnPoolConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrConnPoolGetTimeout = errors.New("ErrConnPoolGetTimeout") ErrConnPoolClosed = errors.New("ErrConnPoolClosed") ErrNoIdleConn = errors.New("NoIdleConn") IdleTimeout = 60 GetConnTimeout = 60 GetConnSleepTime = 100 * time.Millisecond ReDailTimes = 2 )
Functions ¶
func GetCallInArgs ¶
func GetStrSha1 ¶
func GoVarToYJson ¶
func GoVarsToYJsonSlice ¶
Types ¶
type ConnInterface ¶
type ConnInterface interface { Dail(timeout int) error Close() GetId() string // SetId 注意,这个id要存下来。这个id其实是上次使用的时间戳,用于判断是否过期。格式是: {random_int}-{time} SetId(id string) // Clone 复制配置(host,pass等),然后返回指针(注意,必须返回【指针】!!!) Clone() interface{} // IsActive 判断链接是否存活,通常是调用ping。 // 这个操作会浪费一点时间,若觉得不必要或是没有ping方法 也可以直接返回true // 如果直接返回true,使用pool.Get() 返回的链接时注意判断错误,因为链接可能因各种情况关闭。 // 注意!!就算链接已经关闭,仍然需要调用pool.Put() (此时isBad为true),然后再调用pool.Get()重新获取链接 IsActive() bool }
type ConnPool ¶
type ConnPool struct { Conf ConnPoolConfig Conn ConnInterface Mu sync.Mutex IdleConn map[string]interface{} // 用slice会频繁修改,chan比较适合跨协程场景,因此用map Locked bool NumOpen int IsClose bool }
func NewConnPool ¶
func NewConnPool(conn ConnInterface, conf ConnPoolConfig) ConnPool
func (*ConnPool) IsConnTimeout ¶
func (*ConnPool) UpdateConnTime ¶
func (p *ConnPool) UpdateConnTime(conn interface{})
type ConnPoolConfig ¶
type ConnPoolConfig struct { Size int IdleTimeout int // 链接超时时间. Second GetConnTimeout int GetConnSleepTime time.Duration ReDailTimes int // Dail报错的重试次数 }
func NewConnPoolConfig ¶
func NewConnPoolConfig() ConnPoolConfig
Click to show internal directories.
Click to hide internal directories.