mirror of https://github.com/go-redis/redis.git
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"
|
import "github.com/vmihailenco/redis"
|
||||||
|
|
||||||
|
|
||||||
openConn := func() (io.ReadWriteCloser, error) {
|
openConn := func() (net.Conn, error) {
|
||||||
fmt.Println("Connecting...")
|
fmt.Println("Connecting...")
|
||||||
return net.Dial("tcp", ":6379")
|
return net.Dial("tcp", ":6379")
|
||||||
}
|
}
|
||||||
|
|
||||||
closeConn := func(conn io.ReadWriteCloser) error {
|
closeConn := func(conn net.Conn) error {
|
||||||
fmt.Println("Disconnecting...")
|
fmt.Println("Disconnecting...")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package redis
|
package redis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -10,11 +10,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Conn struct {
|
type Conn struct {
|
||||||
RW io.ReadWriteCloser
|
RW net.Conn
|
||||||
Rd reader
|
Rd reader
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConn(rw io.ReadWriteCloser) *Conn {
|
func NewConn(rw net.Conn) *Conn {
|
||||||
return &Conn{
|
return &Conn{
|
||||||
RW: rw,
|
RW: rw,
|
||||||
Rd: bufio.NewReaderSize(rw, 1024),
|
Rd: bufio.NewReaderSize(rw, 1024),
|
||||||
|
|
9
redis.go
9
redis.go
|
@ -2,23 +2,22 @@ package redis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"io"
|
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OpenConnFunc func() (io.ReadWriteCloser, error)
|
type OpenConnFunc func() (net.Conn, error)
|
||||||
type CloseConnFunc func(io.ReadWriteCloser) error
|
type CloseConnFunc func(net.Conn) error
|
||||||
type InitConnFunc func(*Client) error
|
type InitConnFunc func(*Client) error
|
||||||
|
|
||||||
func TCPConnector(addr string) OpenConnFunc {
|
func TCPConnector(addr string) OpenConnFunc {
|
||||||
return func() (io.ReadWriteCloser, error) {
|
return func() (net.Conn, error) {
|
||||||
return net.Dial("tcp", addr)
|
return net.Dial("tcp", addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TLSConnector(addr string, tlsConfig *tls.Config) OpenConnFunc {
|
func TLSConnector(addr string, tlsConfig *tls.Config) OpenConnFunc {
|
||||||
return func() (io.ReadWriteCloser, error) {
|
return func() (net.Conn, error) {
|
||||||
return tls.Dial("tcp", addr, tlsConfig)
|
return tls.Dial("tcp", addr, tlsConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package redis_test
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net"
|
"net"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -41,7 +40,7 @@ func sortStrings(slice []string) []string {
|
||||||
|
|
||||||
func (t *RedisTest) SetUpTest(c *C) {
|
func (t *RedisTest) SetUpTest(c *C) {
|
||||||
if t.client == nil {
|
if t.client == nil {
|
||||||
openConn := func() (io.ReadWriteCloser, error) {
|
openConn := func() (net.Conn, error) {
|
||||||
t.openedConnCount++
|
t.openedConnCount++
|
||||||
return net.Dial("tcp", redisAddr)
|
return net.Dial("tcp", redisAddr)
|
||||||
}
|
}
|
||||||
|
@ -49,7 +48,7 @@ func (t *RedisTest) SetUpTest(c *C) {
|
||||||
t.initedConnCount++
|
t.initedConnCount++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
closeConn := func(conn io.ReadWriteCloser) error {
|
closeConn := func(conn net.Conn) error {
|
||||||
t.closedConnCount++
|
t.closedConnCount++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue