forked from mirror/redis
Merge pull request #110 from go-redis/fix/redis-string-meth
Add Client.String method.
This commit is contained in:
commit
cdfab22180
|
@ -31,11 +31,9 @@ var _ = Describe("ClusterClient", func() {
|
||||||
}
|
}
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
var err error
|
|
||||||
subject = NewClusterClient(&ClusterOptions{
|
subject = NewClusterClient(&ClusterOptions{
|
||||||
Addrs: []string{"127.0.0.1:6379", "127.0.0.1:7003", "127.0.0.1:7006"},
|
Addrs: []string{"127.0.0.1:6379", "127.0.0.1:7003", "127.0.0.1:7006"},
|
||||||
})
|
})
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
AfterEach(func() {
|
AfterEach(func() {
|
||||||
|
|
7
redis.go
7
redis.go
|
@ -1,6 +1,7 @@
|
||||||
package redis // import "gopkg.in/redis.v3"
|
package redis // import "gopkg.in/redis.v3"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
@ -11,6 +12,10 @@ type baseClient struct {
|
||||||
opt *options
|
opt *options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *baseClient) String() string {
|
||||||
|
return fmt.Sprintf("Redis<%s db:%d>", c.opt.Addr, c.opt.DB)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *baseClient) conn() (*conn, error) {
|
func (c *baseClient) conn() (*conn, error) {
|
||||||
return c.connPool.Get()
|
return c.connPool.Get()
|
||||||
}
|
}
|
||||||
|
@ -164,6 +169,7 @@ func (opt *Options) getPoolTimeout() time.Duration {
|
||||||
|
|
||||||
func (opt *Options) options() *options {
|
func (opt *Options) options() *options {
|
||||||
return &options{
|
return &options{
|
||||||
|
Addr: opt.Addr,
|
||||||
Dialer: opt.getDialer(),
|
Dialer: opt.getDialer(),
|
||||||
PoolSize: opt.getPoolSize(),
|
PoolSize: opt.getPoolSize(),
|
||||||
PoolTimeout: opt.getPoolTimeout(),
|
PoolTimeout: opt.getPoolTimeout(),
|
||||||
|
@ -181,6 +187,7 @@ func (opt *Options) options() *options {
|
||||||
}
|
}
|
||||||
|
|
||||||
type options struct {
|
type options struct {
|
||||||
|
Addr string
|
||||||
Dialer func() (net.Conn, error)
|
Dialer func() (net.Conn, error)
|
||||||
PoolSize int
|
PoolSize int
|
||||||
PoolTimeout time.Duration
|
PoolTimeout time.Duration
|
||||||
|
|
|
@ -24,6 +24,10 @@ var _ = Describe("Client", func() {
|
||||||
client.Close()
|
client.Close()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should Stringer", func() {
|
||||||
|
Expect(client.String()).To(Equal("Redis<:6380 db:0>"))
|
||||||
|
})
|
||||||
|
|
||||||
It("should ping", func() {
|
It("should ping", func() {
|
||||||
val, err := client.Ping().Result()
|
val, err := client.Ping().Result()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
Loading…
Reference in New Issue