Rename DialTCP NewTCPClient.

This commit is contained in:
Vladimir Mihailenco 2013-09-29 11:15:18 +03:00
parent f54394beb6
commit 63282071de
3 changed files with 14 additions and 26 deletions

View File

@ -8,7 +8,7 @@ import (
)
func ExampleTCPClient() {
client := redis.DialTCP(&redis.Options{
client := redis.NewTCPClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
@ -21,7 +21,7 @@ func ExampleTCPClient() {
}
func ExampleUnixClient() {
client := redis.DialUnix(&redis.Options{
client := redis.NewUnixClient(&redis.Options{
Addr: "/tmp/redis.sock",
})
defer client.Close()
@ -32,7 +32,7 @@ func ExampleUnixClient() {
}
func ExampleSetGet() {
client := redis.DialTCP(&redis.Options{
client := redis.NewTCPClient(&redis.Options{
Addr: ":6379",
})
defer client.Close()
@ -48,7 +48,7 @@ func ExampleSetGet() {
}
func ExamplePipeline() {
client := redis.DialTCP(&redis.Options{
client := redis.NewTCPClient(&redis.Options{
Addr: ":6379",
})
defer client.Close()
@ -86,7 +86,7 @@ func incr(tx *redis.Multi) ([]redis.Cmder, error) {
}
func ExampleTransaction() {
client := redis.DialTCP(&redis.Options{
client := redis.NewTCPClient(&redis.Options{
Addr: ":6379",
})
defer client.Close()
@ -106,7 +106,7 @@ func ExampleTransaction() {
}
func ExamplePubSub() {
client := redis.DialTCP(&redis.Options{
client := redis.NewTCPClient(&redis.Options{
Addr: ":6379",
})
defer client.Close()
@ -137,7 +137,7 @@ func Get(client *redis.Client, key string) *redis.StringCmd {
}
func ExampleCustomCommand() {
client := redis.DialTCP(&redis.Options{
client := redis.NewTCPClient(&redis.Options{
Addr: ":6379",
})
defer client.Close()

View File

@ -1,7 +1,6 @@
package redis
import (
"crypto/tls"
"log"
"net"
"os"
@ -187,25 +186,14 @@ func newClient(opt *Options, dial func() (net.Conn, error)) *Client {
}
}
func DialTCP(opt *Options) *Client {
func NewTCPClient(opt *Options) *Client {
dial := func() (net.Conn, error) {
return net.DialTimeout("tcp", opt.Addr, opt.getDialTimeout())
}
return newClient(opt, dial)
}
func DialTLS(opt *Options, tlsConfig *tls.Config) *Client {
dial := func() (net.Conn, error) {
conn, err := net.DialTimeout("tcp", opt.Addr, opt.getDialTimeout())
if err != nil {
return nil, err
}
return tls.Client(conn, tlsConfig), nil
}
return newClient(opt, dial)
}
func DialUnix(opt *Options) *Client {
func NewUnixClient(opt *Options) *Client {
dial := func() (net.Conn, error) {
return net.DialTimeout("unix", opt.Addr, opt.getDialTimeout())
}

View File

@ -38,7 +38,7 @@ func (t *RedisConnectionTest) SetUpTest(c *C) {
t.opt = &redis.Options{
Addr: redisAddr,
}
t.client = redis.DialTCP(t.opt)
t.client = redis.NewTCPClient(t.opt)
}
func (t *RedisConnectionTest) TearDownTest(c *C) {
@ -64,7 +64,7 @@ type RedisConnectorTest struct{}
var _ = Suite(&RedisConnectorTest{})
func (t *RedisConnectorTest) TestTCPConnector(c *C) {
client := redis.DialTCP(&redis.Options{
client := redis.NewTCPClient(&redis.Options{
Addr: ":6379",
})
ping := client.Ping()
@ -73,7 +73,7 @@ func (t *RedisConnectorTest) TestTCPConnector(c *C) {
}
func (t *RedisConnectorTest) TestUnixConnector(c *C) {
client := redis.DialUnix(&redis.Options{
client := redis.NewUnixClient(&redis.Options{
Addr: "/tmp/redis.sock",
})
ping := client.Ping()
@ -237,7 +237,7 @@ func Test(t *testing.T) { TestingT(t) }
func (t *RedisTest) SetUpTest(c *C) {
if t.client == nil {
t.client = redis.DialTCP(&redis.Options{
t.client = redis.NewTCPClient(&redis.Options{
Addr: ":6379",
})
}
@ -343,7 +343,7 @@ func (t *RedisTest) TestConnPoolRemovesBrokenConn(c *C) {
c.Assert(err, IsNil)
c.Assert(conn.Close(), IsNil)
client := redis.DialTCP(&redis.Options{
client := redis.NewTCPClient(&redis.Options{
Addr: redisAddr,
})
defer func() {