package redis_test import ( "bytes" "strconv" "sync" "testing" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/shunfei/redis" ) var _ = Describe("Command", func() { var client *redis.Client BeforeEach(func() { client = redis.NewClient(&redis.Options{ Addr: redisAddr, }) }) AfterEach(func() { Expect(client.FlushDb().Err()).NotTo(HaveOccurred()) Expect(client.Close()).NotTo(HaveOccurred()) }) It("should implement Stringer", func() { set := client.Set("foo", "bar", 0) Expect(set.String()).To(Equal("SET foo bar: OK"))
package redis_test import ( "net" "sync" "time" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/shunfei/redis" ) var _ = Describe("PubSub", func() { var client *redis.Client readTimeout := 3 * time.Second BeforeEach(func() { client = redis.NewClient(&redis.Options{ Addr: redisAddr, ReadTimeout: readTimeout, }) Expect(client.FlushDb().Err()).NotTo(HaveOccurred()) }) AfterEach(func() { Expect(client.Close()).NotTo(HaveOccurred()) }) It("should support pattern matching", func() { pubsub, err := client.PSubscribe("mychannel*") Expect(err).NotTo(HaveOccurred())
package redis_test import ( "strconv" "sync" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/shunfei/redis" ) var _ = Describe("Pipelining", func() { var client *redis.Client BeforeEach(func() { client = redis.NewClient(&redis.Options{ Addr: redisAddr, }) }) AfterEach(func() { Expect(client.FlushDb().Err()).NotTo(HaveOccurred()) Expect(client.Close()).NotTo(HaveOccurred()) }) It("should pipeline", func() { set := client.Set("key2", "hello2", 0) Expect(set.Err()).NotTo(HaveOccurred()) Expect(set.Val()).To(Equal("OK")) pipeline := client.Pipeline()
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"))
package redis_test import ( "errors" "sync" "testing" "time" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/shunfei/redis" ) var _ = Describe("pool", func() { var client *redis.Client var perform = func(n int, cb func()) { wg := &sync.WaitGroup{} for i := 0; i < n; i++ { wg.Add(1) go func() { defer GinkgoRecover() defer wg.Done() cb() }() } wg.Wait() } BeforeEach(func() {
package redis_test import ( "strconv" "sync" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/shunfei/redis" ) var _ = Describe("Multi", func() { var client *redis.Client BeforeEach(func() { client = redis.NewClient(&redis.Options{ Addr: redisAddr, }) }) AfterEach(func() { Expect(client.FlushDb().Err()).NotTo(HaveOccurred()) Expect(client.Close()).NotTo(HaveOccurred()) }) It("should Watch", func() { var incr func(string) error // Transactionally increments key using GET and SET commands. incr = func(key string) error { tx, err := client.Watch(key)
package redis_test import ( "bytes" "net" "testing" "time" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/shunfei/redis" ) var _ = Describe("Client", func() { var client *redis.Client BeforeEach(func() { client = redis.NewClient(&redis.Options{ Addr: redisAddr, }) }) AfterEach(func() { client.Close() }) It("should Stringer", func() { Expect(client.String()).To(Equal("Redis<:6380 db:0>")) }) It("should ping", func() {