Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aosen/gopool
go连接池、Golang连接池、By Golang realize distributed common connection pool.
https://github.com/aosen/gopool
connection-pool golang
Last synced: 2 months ago
JSON representation
go连接池、Golang连接池、By Golang realize distributed common connection pool.
- Host: GitHub
- URL: https://github.com/aosen/gopool
- Owner: aosen
- License: apache-2.0
- Created: 2017-03-03T09:28:39.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-19T10:00:25.000Z (over 6 years ago)
- Last Synced: 2024-08-04T06:01:09.243Z (6 months ago)
- Topics: connection-pool, golang
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 82
- Watchers: 5
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- xiao-awesome - gopool
README
# gopool
* By Golang realize distributed common connection pool.
* Golang分布式的连接池,协程池,内含redis client连接池实现* go get github.com/aosen/gopool
## example
```
var addrs []string = []string{"127.0.0.1:8000", "127.0.0.1:8001", "127.0.0.1:8002", "127.0.0.1:8003"}var epool Pooler
func InitExpPool() (err error) {
if epool == nil {
epool, err = NewChanConnPool(&ConnPoolReq{
Addrs: addrs,
Create: func(addr string, timeout time.Duration) (interface{}, error) {
cli, err := net.DialTimeout("tcp", addr, timeout)
return cli, err
},
IsOpen: func(cli interface{}) bool {
if cli != nil {
return true
}
return false
},
Down: func(cli interface{}) {
c := cli.(net.Conn)
c.Close()
},
})
return
}
return
}func Get() (cli net.Conn, err error) {
if epool == nil {
err = errors.New("no init epool.")
return
}
cli, err = epool.Get()
return
}func Put(cli net.Conn, safe bool) {
if epool == nil {
err := errors.New("no init epool.")
return
}
epool.Put(cli, safe)
}func GetHealthy() map[string]bool {
if epool == nil {
return nil
}
return epool.GetHealthy()
}func GetConnCount() map[string]int {
if epool == nil {
return nil
}
return epool.GetConnCount()
}
```