go client add conn buffer size config

This commit is contained in:
siddontang 2014-10-25 15:27:05 +08:00
parent 37453395b2
commit 8889197a39
3 changed files with 13 additions and 3 deletions

View File

@ -12,8 +12,10 @@ const (
)
type Config struct {
Addr string
MaxIdleConns int
Addr string
MaxIdleConns int
ReadBufferSize int
WriteBufferSize int
}
type Client struct {
@ -36,6 +38,12 @@ func NewClient(cfg *Config) *Client {
c := new(Client)
c.cfg = cfg
if c.cfg.ReadBufferSize == 0 {
c.cfg.ReadBufferSize = 4096
}
if c.cfg.WriteBufferSize == 0 {
c.cfg.WriteBufferSize = 4096
}
c.conns = list.New()

View File

@ -384,7 +384,7 @@ func (c *Conn) readReply() (interface{}, error) {
}
func (c *Client) newConn(addr string) *Conn {
co := NewConn(addr)
co := NewConnSize(addr, c.cfg.ReadBufferSize, c.cfg.WriteBufferSize)
co.client = c
return co

View File

@ -268,6 +268,8 @@ func main() {
cfg := new(ledis.Config)
cfg.Addr = addr
cfg.MaxIdleConns = *clients
cfg.ReadBufferSize = 10240
cfg.WriteBufferSize = 10240
client = ledis.NewClient(cfg)
if *round <= 0 {