Skip to content

Instantly share code, notes, and snippets.

@zlwu
Created May 14, 2015 05:00
Show Gist options
  • Save zlwu/1b7c0a3624546af70898 to your computer and use it in GitHub Desktop.
Save zlwu/1b7c0a3624546af70898 to your computer and use it in GitHub Desktop.
// a pool embedding the original pool and adding adbno state
type DbnoPool struct {
redis.Pool
dbno int
}
// "overriding" the Get method
func (p *DbnoPool)Get() Connection {
conn := p.Pool.Get()
conn.Do("SELECT", p.dbno)
return conn
}
pool := &DbnoPool {
redis.Pool{
MaxIdle: 80,
MaxActive: 12000, // max number of connections
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", host+":"+port)
if err != nil {
panic(err.Error())
}
return c, err
},
3, // the db number
}
//now you call it normally
conn := pool.Get()
defer conn.Close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment