From f56748aab9bc50fdfdc8ccc7e68a1adb1418967b Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Mon, 20 Aug 2012 14:46:41 +0300 Subject: [PATCH] Use net.Conn instead of io.ReadWriteCloser. --- README.md | 4 ++-- connpool.go | 6 +++--- redis.go | 9 ++++----- redis_test.go | 5 ++--- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index f655d144..436251a8 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,12 @@ Example 2: import "github.com/vmihailenco/redis" - openConn := func() (io.ReadWriteCloser, error) { + openConn := func() (net.Conn, error) { fmt.Println("Connecting...") return net.Dial("tcp", ":6379") } - closeConn := func(conn io.ReadWriteCloser) error { + closeConn := func(conn net.Conn) error { fmt.Println("Disconnecting...") return nil } diff --git a/connpool.go b/connpool.go index a3183f53..15154c6b 100644 --- a/connpool.go +++ b/connpool.go @@ -1,8 +1,8 @@ package redis import ( - "io" "log" + "net" "os" "sync" @@ -10,11 +10,11 @@ import ( ) type Conn struct { - RW io.ReadWriteCloser + RW net.Conn Rd reader } -func NewConn(rw io.ReadWriteCloser) *Conn { +func NewConn(rw net.Conn) *Conn { return &Conn{ RW: rw, Rd: bufio.NewReaderSize(rw, 1024), diff --git a/redis.go b/redis.go index 8046b911..9dde6598 100644 --- a/redis.go +++ b/redis.go @@ -2,23 +2,22 @@ package redis import ( "crypto/tls" - "io" "net" "sync" ) -type OpenConnFunc func() (io.ReadWriteCloser, error) -type CloseConnFunc func(io.ReadWriteCloser) error +type OpenConnFunc func() (net.Conn, error) +type CloseConnFunc func(net.Conn) error type InitConnFunc func(*Client) error func TCPConnector(addr string) OpenConnFunc { - return func() (io.ReadWriteCloser, error) { + return func() (net.Conn, error) { return net.Dial("tcp", addr) } } func TLSConnector(addr string, tlsConfig *tls.Config) OpenConnFunc { - return func() (io.ReadWriteCloser, error) { + return func() (net.Conn, error) { return tls.Dial("tcp", addr, tlsConfig) } } diff --git a/redis_test.go b/redis_test.go index f1bb2040..de6d5956 100644 --- a/redis_test.go +++ b/redis_test.go @@ -3,7 +3,6 @@ package redis_test import ( "bytes" "fmt" - "io" "net" "runtime" "sort" @@ -41,7 +40,7 @@ func sortStrings(slice []string) []string { func (t *RedisTest) SetUpTest(c *C) { if t.client == nil { - openConn := func() (io.ReadWriteCloser, error) { + openConn := func() (net.Conn, error) { t.openedConnCount++ return net.Dial("tcp", redisAddr) } @@ -49,7 +48,7 @@ func (t *RedisTest) SetUpTest(c *C) { t.initedConnCount++ return nil } - closeConn := func(conn io.ReadWriteCloser) error { + closeConn := func(conn net.Conn) error { t.closedConnCount++ return nil }