From 91e4e661aac5b40703ab980f3a308f72e582df80 Mon Sep 17 00:00:00 2001 From: Vlad Hanciuta Date: Thu, 20 Jan 2011 23:12:15 +0100 Subject: [PATCH] Made MaxPoolSize member of Client struct, so that pool size is configurable at runtime. --- redis.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/redis.go b/redis.go index bf60a96..408b564 100644 --- a/redis.go +++ b/redis.go @@ -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 } @@ -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 }