Skip to content

Commit

Permalink
Add Client.String method.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed May 18, 2015
1 parent c1033ea commit f531b3b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 0 additions & 2 deletions cluster_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 7 additions & 0 deletions redis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package redis // import "gopkg.in/redis.v3"

import (
"fmt"
"log"
"net"
"time"
Expand All @@ -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()
}
Expand Down Expand Up @@ -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(),
Expand All @@ -181,6 +187,7 @@ func (opt *Options) options() *options {
}

type options struct {
Addr string
Dialer func() (net.Conn, error)
PoolSize int
PoolTimeout time.Duration
Expand Down
4 changes: 4 additions & 0 deletions redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit f531b3b

Please sign in to comment.