Add example for failover client.

This commit is contained in:
Vladimir Mihailenco 2014-07-13 15:49:33 +03:00
parent 2651b57a91
commit ffe62d60e2
5 changed files with 25 additions and 5 deletions

View File

@ -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 &

View File

@ -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
-------------

View File

@ -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)

View File

@ -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 {

6
testdata/sentinel.conf vendored Normal file
View File

@ -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