Пример #1
0
func workerGetSetRand(client *memcache.Client, wg *sync.WaitGroup, ch <-chan int) {
	defer wg.Done()
	var item memcache.Item
	itemsCount := *requestsCount / *workersCount
	for _ = range ch {
		n := rand.Intn(itemsCount)
		item.Key = []byte(fmt.Sprintf("%s_%d", *key, n))
		v := []byte(fmt.Sprintf("%s_%d", *value, n))
		if rand.Float32() < 0.5 {
			err := client.Get(&item)
			if err == memcache.ErrCacheMiss {
				continue
			}
			if err != nil {
				log.Fatalf("Error in Client.Get(): [%s]", err)
			}
			if !bytes.Equal(item.Value, v) {
				log.Fatalf("Unexpected value=[%s] obtained. Expected [%s]", item.Value, v)
			}
		} else {
			item.Value = v
			if err := client.Set(&item); err != nil {
				log.Fatalf("Error in Client.Set(): [%s]", err)
			}
		}
	}
}
Пример #2
0
func workerGetMiss(client *memcache.Client, wg *sync.WaitGroup, ch <-chan int) {
	defer wg.Done()
	item := memcache.Item{
		Key: []byte(*key),
	}
	for _ = range ch {
		if err := client.Get(&item); err != memcache.ErrCacheMiss {
			log.Fatalf("Error in Client.Get(): [%s]", err)
		}
	}
}
Пример #3
0
func workerGetHit(client *memcache.Client, wg *sync.WaitGroup, ch <-chan int) {
	defer wg.Done()
	item := memcache.Item{
		Key:   []byte(*key),
		Value: []byte(*value),
	}
	valueOrig := item.Value
	item.Value = nil
	for _ = range ch {
		if err := client.Get(&item); err != nil {
			log.Fatalf("Error in Client.Get(): [%s]", err)
		}
		if !bytes.Equal(valueOrig, item.Value) {
			log.Fatalf("Unexpected value read=[%s]. Expected=[%s]", item.Value, valueOrig)
		}
	}
}