From ffe62d60e2dac87af57a6726ed01c82616abb929 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sun, 13 Jul 2014 15:49:33 +0300 Subject: [PATCH] Add example for failover client. --- .travis.yml | 3 +++ README.md | 7 ++++--- example_test.go | 12 +++++++++++- sentinel_test.go | 2 +- testdata/sentinel.conf | 6 ++++++ 5 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 testdata/sentinel.conf diff --git a/.travis.yml b/.travis.yml index 32ac653..0b3f817 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 & diff --git a/README.md b/README.md index efae65d..ddf875f 100644 --- a/README.md +++ b/README.md @@ -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 ------------- diff --git a/example_test.go b/example_test.go index 0b283fa..0a7f0bc 100644 --- a/example_test.go +++ b/example_test.go @@ -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 +} + +func ExampleNewFailoverClient() { + client := redis.NewFailoverClient(&redis.FailoverOptions{ + MasterName: "master", + SentinelAddrs: []string{":26379"}, + }) pong, err := client.Ping().Result() fmt.Println(pong, err) diff --git a/sentinel_test.go b/sentinel_test.go index e2f93ad..ae317b7 100644 --- a/sentinel_test.go +++ b/sentinel_test.go @@ -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 { diff --git a/testdata/sentinel.conf b/testdata/sentinel.conf new file mode 100644 index 0000000..3da90b3 --- /dev/null +++ b/testdata/sentinel.conf @@ -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