mirror of
https://github.com/redis/go-redis.git
synced 2025-06-12 14:21:52 +03:00
Add example for failover client.
This commit is contained in:
@ -15,3 +15,6 @@ install:
|
|||||||
- go get gopkg.in/check.v1
|
- go get gopkg.in/check.v1
|
||||||
- mkdir -p $HOME/gopath/src/gopkg.in
|
- mkdir -p $HOME/gopath/src/gopkg.in
|
||||||
- ln -s `pwd` $HOME/gopath/src/gopkg.in/redis.v2
|
- 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.
|
- TLS connections.
|
||||||
- Thread safety.
|
- Thread safety.
|
||||||
- Timeouts.
|
- Timeouts.
|
||||||
|
- Redis Sentinel.
|
||||||
|
|
||||||
API docs: http://godoc.org/gopkg.in/redis.v1.
|
API docs: http://godoc.org/gopkg.in/redis.v2.
|
||||||
Examples: http://godoc.org/gopkg.in/redis.v1#pkg-examples.
|
Examples: http://godoc.org/gopkg.in/redis.v2#pkg-examples.
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Install:
|
Install:
|
||||||
|
|
||||||
go get gopkg.in/redis.v1
|
go get gopkg.in/redis.v2
|
||||||
|
|
||||||
Look and feel
|
Look and feel
|
||||||
-------------
|
-------------
|
||||||
|
@ -22,7 +22,17 @@ func ExampleNewTCPClient() {
|
|||||||
Password: "", // no password set
|
Password: "", // no password set
|
||||||
DB: 0, // use default DB
|
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()
|
pong, err := client.Ping().Result()
|
||||||
fmt.Println(pong, err)
|
fmt.Println(pong, err)
|
||||||
|
@ -86,7 +86,7 @@ func TestSentinel(t *testing.T) {
|
|||||||
masterName := "mymaster"
|
masterName := "mymaster"
|
||||||
masterPort := "8123"
|
masterPort := "8123"
|
||||||
slavePort := "8124"
|
slavePort := "8124"
|
||||||
sentinelPort := "26379"
|
sentinelPort := "8125"
|
||||||
|
|
||||||
_, err := startRedis(masterPort)
|
_, err := startRedis(masterPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
6
testdata/sentinel.conf
vendored
Normal file
6
testdata/sentinel.conf
vendored
Normal 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
|
Reference in New Issue
Block a user