mirror of https://github.com/go-redis/redis.git
Add NewUnixClient to connect to the unix sockets.
This commit is contained in:
parent
9f494b20b1
commit
f64761880b
10
redis.go
10
redis.go
|
@ -32,6 +32,12 @@ func TLSConnector(addr string, tlsConfig *tls.Config) OpenConnFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UnixConnector(addr string) OpenConnFunc {
|
||||||
|
return func() (net.Conn, error) {
|
||||||
|
return net.DialTimeout("unix", addr, 3*time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func AuthSelectFunc(password string, db int64) InitConnFunc {
|
func AuthSelectFunc(password string, db int64) InitConnFunc {
|
||||||
if password == "" && db < 0 {
|
if password == "" && db < 0 {
|
||||||
return nil
|
return nil
|
||||||
|
@ -182,3 +188,7 @@ func NewTLSClient(addr string, tlsConfig *tls.Config, password string, db int64)
|
||||||
AuthSelectFunc(password, db),
|
AuthSelectFunc(password, db),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewUnixClient(addr string, password string, db int64) *Client {
|
||||||
|
return NewClient(UnixConnector(addr), nil, AuthSelectFunc(password, db))
|
||||||
|
}
|
||||||
|
|
|
@ -52,9 +52,30 @@ func (t *RedisShutdownTest) TestShutdown(c *C) {
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
type RedisConnectorTest struct{}
|
||||||
|
|
||||||
|
var _ = Suite(&RedisConnectorTest{})
|
||||||
|
|
||||||
|
func (t *RedisConnectorTest) TestTCPConnector(c *C) {
|
||||||
|
client := redis.NewTCPClient(":6379", "", -1)
|
||||||
|
ping := client.Ping()
|
||||||
|
c.Check(ping.Err(), IsNil)
|
||||||
|
c.Check(ping.Val(), Equals, "PONG")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *RedisConnectorTest) TestUnixConnector(c *C) {
|
||||||
|
client := redis.NewUnixClient("/tmp/redis.sock", "", -1)
|
||||||
|
ping := client.Ping()
|
||||||
|
c.Check(ping.Err(), IsNil)
|
||||||
|
c.Check(ping.Val(), Equals, "PONG")
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
type RedisConnPoolTest struct {
|
type RedisConnPoolTest struct {
|
||||||
openedConnCount, closedConnCount, initedConnCount int64
|
openedConnCount, closedConnCount, initedConnCount int64
|
||||||
client *redis.Client
|
|
||||||
|
client *redis.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = Suite(&RedisConnPoolTest{})
|
var _ = Suite(&RedisConnPoolTest{})
|
||||||
|
@ -2734,7 +2755,7 @@ func (t *RedisTest) TestScriptingScriptFlush(c *C) {
|
||||||
|
|
||||||
func (t *RedisTest) TestScriptingScriptKill(c *C) {
|
func (t *RedisTest) TestScriptingScriptKill(c *C) {
|
||||||
scriptKill := t.client.ScriptKill()
|
scriptKill := t.client.ScriptKill()
|
||||||
c.Assert(scriptKill.Err(), ErrorMatches, "ERR No scripts in execution right now.")
|
c.Assert(scriptKill.Err(), ErrorMatches, ".*No scripts in execution right now.")
|
||||||
c.Assert(scriptKill.Val(), Equals, "")
|
c.Assert(scriptKill.Val(), Equals, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue