本文整理汇总了Golang中github.com/valyala/ybc/libs/go/memcache.Item.Value方法的典型用法代码示例。如果您正苦于以下问题:Golang Item.Value方法的具体用法?Golang Item.Value怎么用?Golang Item.Value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/valyala/ybc/libs/go/memcache.Item
的用法示例。
在下文中一共展示了Item.Value方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: workerGetSetRand
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: workerGetSetNew
func workerGetSetNew(client memcache_new.Cacher, wg *sync.WaitGroup, ch <-chan int, stats *Stats) {
defer wg.Done()
var item memcache_new.Item
for _ = range ch {
n := rand.Intn(*itemsCount)
item.Key = []byte(fmt.Sprintf("%s_%d", key, n))
startTime := time.Now()
if rand.Float64() < *getRatio {
err := client.Get(&item)
if err == memcache_new.ErrCacheMiss {
stats.cacheMissCount++
continue
}
if err != nil {
stats.errorsCount++
continue
}
stats.cacheHitCount++
updateResponseTimeHistogram(stats, startTime)
} else {
item.Value = value
if err := client.Set(&item); err != nil {
stats.errorsCount++
continue
}
updateResponseTimeHistogram(stats, startTime)
}
}
}
示例3: workerSet
func workerSet(client *memcache.Client, wg *sync.WaitGroup, ch <-chan int) {
defer wg.Done()
var item memcache.Item
for i := range ch {
item.Key = []byte(fmt.Sprintf("%s_%d", *key, i))
item.Value = []byte(fmt.Sprintf("%s_%d", *value, i))
if err := client.Set(&item); err != nil {
log.Fatalf("Error in Client.Set(): [%s]", err)
}
}
}
示例4: workerSetNew
func workerSetNew(client memcache_new.Cacher, wg *sync.WaitGroup, ch <-chan int, stats *Stats) {
defer wg.Done()
var item memcache_new.Item
for _ = range ch {
n := rand.Intn(*itemsCount)
item.Key = []byte(fmt.Sprintf("%s_%d", key, n))
item.Value = value
startTime := time.Now()
if err := client.Set(&item); err != nil {
stats.errorsCount++
continue
}
updateResponseTimeHistogram(stats, startTime)
}
}
示例5: workerGetHit
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)
}
}
}