1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-29 17:41:15 +03:00

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

View File

@ -1,7 +1,6 @@
package redis package redis
import ( import (
"crypto/tls"
"log" "log"
"net" "net"
"os" "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) { dial := func() (net.Conn, error) {
return net.DialTimeout("tcp", opt.Addr, opt.getDialTimeout()) return net.DialTimeout("tcp", opt.Addr, opt.getDialTimeout())
} }
return newClient(opt, dial) return newClient(opt, dial)
} }
func DialTLS(opt *Options, tlsConfig *tls.Config) *Client { func NewUnixClient(opt *Options) *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 {
dial := func() (net.Conn, error) { dial := func() (net.Conn, error) {
return net.DialTimeout("unix", opt.Addr, opt.getDialTimeout()) return net.DialTimeout("unix", opt.Addr, opt.getDialTimeout())
} }

View File

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