forked from mirror/redis
Use net.Conn instead of io.ReadWriteCloser.
This commit is contained in:
parent
9ad848d04b
commit
f56748aab9
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
9
redis.go
9
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue