forked from mirror/redis
Reuse write buffer.
This commit is contained in:
parent
aff229a228
commit
97039c229c
2
pool.go
2
pool.go
|
@ -35,6 +35,7 @@ type pool interface {
|
||||||
type conn struct {
|
type conn struct {
|
||||||
netcn net.Conn
|
netcn net.Conn
|
||||||
rd *bufio.Reader
|
rd *bufio.Reader
|
||||||
|
buf []byte
|
||||||
|
|
||||||
inUse bool
|
inUse bool
|
||||||
usedAt time.Time
|
usedAt time.Time
|
||||||
|
@ -53,6 +54,7 @@ func newConnFunc(dial func() (net.Conn, error)) func() (*conn, error) {
|
||||||
}
|
}
|
||||||
cn := &conn{
|
cn := &conn{
|
||||||
netcn: netcn,
|
netcn: netcn,
|
||||||
|
buf: make([]byte, 0, 64),
|
||||||
}
|
}
|
||||||
cn.rd = bufio.NewReader(cn)
|
cn.rd = bufio.NewReader(cn)
|
||||||
return cn, nil
|
return cn, nil
|
||||||
|
|
2
redis.go
2
redis.go
|
@ -14,7 +14,7 @@ type baseClient struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *baseClient) writeCmd(cn *conn, cmds ...Cmder) error {
|
func (c *baseClient) writeCmd(cn *conn, cmds ...Cmder) error {
|
||||||
buf := make([]byte, 0, 64)
|
buf := cn.buf[:0]
|
||||||
for _, cmd := range cmds {
|
for _, cmd := range cmds {
|
||||||
buf = appendArgs(buf, cmd.args())
|
buf = appendArgs(buf, cmd.args())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue