forked from mirror/redis
Add example for failover client.
This commit is contained in:
parent
2651b57a91
commit
ffe62d60e2
|
@ -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 &
|
||||
|
|
|
@ -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
|
||||
-------------
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue