コード例 #1
0
ファイル: command_test.go プロジェクト: chinaweilu/dk
	var client *redis.Client

	BeforeEach(func() {
		client = redis.NewClient(redisOptions())
		Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
	})

	AfterEach(func() {
		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"))

		get := client.Get("foo")
		Expect(get.String()).To(Equal("GET foo: bar"))
	})

	It("should have correct val/err states", func() {
		set := client.Set("key", "hello", 0)
		Expect(set.Err()).NotTo(HaveOccurred())
		Expect(set.Val()).To(Equal("OK"))

		get := client.Get("key")
		Expect(get.Err()).NotTo(HaveOccurred())
		Expect(get.Val()).To(Equal("hello"))

		Expect(set.Err()).NotTo(HaveOccurred())
		Expect(set.Val()).To(Equal("OK"))
	})
コード例 #2
0
ファイル: pipeline_test.go プロジェクト: chinaweilu/dk
		key := "TestPipelineIncr"
		pipeline := client.Pipeline()
		for i := 0; i < N; i++ {
			pipeline.Incr(key)
		}

		cmds, err := pipeline.Exec()
		Expect(err).NotTo(HaveOccurred())
		Expect(pipeline.Close()).NotTo(HaveOccurred())

		Expect(len(cmds)).To(Equal(20000))
		for _, cmd := range cmds {
			Expect(cmd.Err()).NotTo(HaveOccurred())
		}

		get := client.Get(key)
		Expect(get.Err()).NotTo(HaveOccurred())
		Expect(get.Val()).To(Equal(strconv.Itoa(N)))
	})

	It("should PipelineEcho", func() {
		const N = 1000

		wg := &sync.WaitGroup{}
		wg.Add(N)
		for i := 0; i < N; i++ {
			go func(i int) {
				defer GinkgoRecover()
				defer wg.Done()

				pipeline := client.Pipeline()
コード例 #3
0
ファイル: multi_test.go プロジェクト: chinaweilu/dk
		}

		var wg sync.WaitGroup
		for i := 0; i < 100; i++ {
			wg.Add(1)
			go func() {
				defer GinkgoRecover()
				defer wg.Done()

				err := incr("key")
				Expect(err).NotTo(HaveOccurred())
			}()
		}
		wg.Wait()

		n, err := client.Get("key").Int64()
		Expect(err).NotTo(HaveOccurred())
		Expect(n).To(Equal(int64(100)))
	})

	It("should discard", func() {
		multi := client.Multi()
		defer func() {
			Expect(multi.Close()).NotTo(HaveOccurred())
		}()

		cmds, err := multi.Exec(func() error {
			multi.Set("key1", "hello1", 0)
			multi.Discard()
			multi.Set("key2", "hello2", 0)
			return nil