Skip to content

Commit

Permalink
Add example for failover client.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Jul 13, 2014
1 parent 2651b57 commit ffe62d6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ install:
- go get gopkg.in/check.v1
- mkdir -p $HOME/gopath/src/gopkg.in
- ln -s `pwd` $HOME/gopath/src/gopkg.in/redis.v2

before_script:
- redis-server testdata/sentinel.conf --sentinel &
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ Supports:
- TLS connections.
- Thread safety.
- Timeouts.
- Redis Sentinel.

API docs: http://godoc.org/gopkg.in/redis.v1.
Examples: http://godoc.org/gopkg.in/redis.v1#pkg-examples.
API docs: http://godoc.org/gopkg.in/redis.v2.
Examples: http://godoc.org/gopkg.in/redis.v2#pkg-examples.

Installation
------------

Install:

go get gopkg.in/redis.v1
go get gopkg.in/redis.v2

Look and feel
-------------
Expand Down
12 changes: 11 additions & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ func ExampleNewTCPClient() {
Password: "", // no password set
DB: 0, // use default DB
})
defer client.Close()

pong, err := client.Ping().Result()
fmt.Println(pong, err)
// Output: PONG <nil>
}

func ExampleNewFailoverClient() {
client := redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: "master",
SentinelAddrs: []string{":26379"},
})

pong, err := client.Ping().Result()
fmt.Println(pong, err)
Expand Down
2 changes: 1 addition & 1 deletion sentinel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestSentinel(t *testing.T) {
masterName := "mymaster"
masterPort := "8123"
slavePort := "8124"
sentinelPort := "26379"
sentinelPort := "8125"

_, err := startRedis(masterPort)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions testdata/sentinel.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
port 26379

sentinel monitor master 127.0.0.1 6379 1
sentinel down-after-milliseconds master 2000
sentinel failover-timeout master 5000
sentinel parallel-syncs master 4

0 comments on commit ffe62d6

Please sign in to comment.