Ejemplo n.º 1
0
	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())
		defer pubsub.Close()

		n, err := client.Publish("mychannel1", "hello").Result()
		Expect(err).NotTo(HaveOccurred())
		Expect(n).To(Equal(int64(1)))

		Expect(pubsub.PUnsubscribe("mychannel*")).NotTo(HaveOccurred())

		{
			msgi, err := pubsub.ReceiveTimeout(time.Second)
			Expect(err).NotTo(HaveOccurred())
			subscr := msgi.(*redis.Subscription)
			Expect(subscr.Kind).To(Equal("psubscribe"))
			Expect(subscr.Channel).To(Equal("mychannel*"))