Esempio n. 1
0
		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)
			if err != nil {
				return err
			}
			defer tx.Close()

			n, err := tx.Get(key).Int64()
			if err != nil && err != redis.Nil {
				return err
			}

			_, err = tx.Exec(func() error {
				tx.Set(key, strconv.FormatInt(n+1, 10), 0)
				return nil
			})
			if err == redis.TxFailedErr {