Skip to content

Commit

Permalink
Made MaxPoolSize member of Client struct, so that pool size is config…
Browse files Browse the repository at this point in the history
…urable at runtime.
  • Loading branch information
wladh committed Jan 20, 2011
1 parent 695e327 commit 91e4e66
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ import (
)

const (
MaxPoolSize = 5
defaultPoolSize = 5
)

var defaultAddr, _ = net.ResolveTCPAddr("127.0.0.1:7379")

type Client struct {
Addr string
Db int
Password string
Addr string
Db int
Password string
MaxPoolSize int
//the connection pool
pool chan *net.TCPConn
}
Expand Down Expand Up @@ -297,8 +298,12 @@ End:

func (client *Client) popCon() (*net.TCPConn, os.Error) {
if client.pool == nil {
client.pool = make(chan *net.TCPConn, MaxPoolSize)
for i := 0; i < MaxPoolSize; i++ {
poolSize := client.MaxPoolSize
if poolSize == 0 {
poolSize = defaultPoolSize
}
client.pool = make(chan *net.TCPConn, poolSize)
for i := 0; i < poolSize; i++ {
//add dummy values to the pool
client.pool <- nil
}
Expand Down

0 comments on commit 91e4e66

Please sign in to comment.