From f531b3b493be57f112a4e29cd440f599b7392172 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Fri, 15 May 2015 15:21:28 +0300 Subject: [PATCH] Add Client.String method. --- cluster_client_test.go | 2 -- redis.go | 7 +++++++ redis_test.go | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cluster_client_test.go b/cluster_client_test.go index e9ea16c..c7f695d 100644 --- a/cluster_client_test.go +++ b/cluster_client_test.go @@ -31,11 +31,9 @@ var _ = Describe("ClusterClient", func() { } BeforeEach(func() { - var err error subject = NewClusterClient(&ClusterOptions{ Addrs: []string{"127.0.0.1:6379", "127.0.0.1:7003", "127.0.0.1:7006"}, }) - Expect(err).NotTo(HaveOccurred()) }) AfterEach(func() { diff --git a/redis.go b/redis.go index 3cc5841..4186ffb 100644 --- a/redis.go +++ b/redis.go @@ -1,6 +1,7 @@ package redis // import "gopkg.in/redis.v3" import ( + "fmt" "log" "net" "time" @@ -11,6 +12,10 @@ type baseClient struct { 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) { return c.connPool.Get() } @@ -164,6 +169,7 @@ func (opt *Options) getPoolTimeout() time.Duration { func (opt *Options) options() *options { return &options{ + Addr: opt.Addr, Dialer: opt.getDialer(), PoolSize: opt.getPoolSize(), PoolTimeout: opt.getPoolTimeout(), @@ -181,6 +187,7 @@ func (opt *Options) options() *options { } type options struct { + Addr string Dialer func() (net.Conn, error) PoolSize int PoolTimeout time.Duration diff --git a/redis_test.go b/redis_test.go index 5fb6d65..4ad4486 100644 --- a/redis_test.go +++ b/redis_test.go @@ -24,6 +24,10 @@ var _ = Describe("Client", func() { client.Close() }) + It("should Stringer", func() { + Expect(client.String()).To(Equal("Redis<:6380 db:0>")) + }) + It("should ping", func() { val, err := client.Ping().Result() Expect(err).NotTo(HaveOccurred())