func ExampleNewFailoverClient() { // See http://redis.io/topics/sentinel for instructions how to // setup Redis Sentinel. client := redis.NewFailoverClient(&redis.FailoverOptions{ MasterName: "master", SentinelAddrs: []string{":26379"}, }) client.Ping() }
package redis_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/shunfei/redis" ) var _ = Describe("Sentinel", func() { var client *redis.Client BeforeEach(func() { client = redis.NewFailoverClient(&redis.FailoverOptions{ MasterName: sentinelName, SentinelAddrs: []string{":" + sentinelPort}, }) }) AfterEach(func() { Expect(client.Close()).NotTo(HaveOccurred()) }) It("should facilitate failover", func() { // Set value on master, verify err := client.Set("foo", "master", 0).Err() Expect(err).NotTo(HaveOccurred()) val, err := sentinelMaster.Get("foo").Result() Expect(err).NotTo(HaveOccurred()) Expect(val).To(Equal("master"))