当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.Set方法代码示例

本文整理汇总了Golang中github.com/bradfitz/gomemcache/memcache.Client.Set方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Set方法的具体用法?Golang Client.Set怎么用?Golang Client.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/bradfitz/gomemcache/memcache.Client的用法示例。


在下文中一共展示了Client.Set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: workerGetSetOrg

func workerGetSetOrg(client *memcache_org.Client, wg *sync.WaitGroup, ch <-chan int, stats *Stats) {
	defer wg.Done()
	var item memcache_org.Item
	for _ = range ch {
		n := rand.Intn(*itemsCount)
		item.Key = fmt.Sprintf("%s_%d", key, n)
		startTime := time.Now()
		if rand.Float64() < *getRatio {
			_, err := client.Get(item.Key)
			if err == memcache_org.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)
		}
	}
}
开发者ID:jjoergensen,项目名称:ybc,代码行数:29,代码来源:main.go

示例2: workerSetOrg

func workerSetOrg(client *memcache_org.Client, wg *sync.WaitGroup, ch <-chan int, stats *Stats) {
	defer wg.Done()
	var item memcache_org.Item
	for _ = range ch {
		n := rand.Intn(*itemsCount)
		item.Key = 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)
	}
}
开发者ID:jjoergensen,项目名称:ybc,代码行数:15,代码来源:main.go

示例3: setTestSingle

func setTestSingle(ch chan bool, mc *memcache.Client, cn, n int) {
	var err error
	v := make([]byte, dataSize)
	for i := 0; i < n; i++ {
		start := time.Now()
		err = mc.Set(&memcache.Item{Key: topicName, Value: v})
		if err != nil {
			log.Printf("set error: c%d %v", cn, err)
		} else {
			end := time.Now()
			duration := end.Sub(start).Seconds()
			log.Printf("set succ: %s spend: %.3fms", topicName, duration*1000)
		}
	}
	ch <- true
}
开发者ID:henser123,项目名称:uq,代码行数:16,代码来源:mc_bench_sc.go

示例4: SetCachedRequest

// Store the result of an API request in memcached.
func SetCachedRequest(m *memcache.Client, key string, value *ApiResult) {
	// Don't cache errors
	if value.Success == 0 {
		return
	}
	result_json, err := json.MarshalIndent(value, "", "  ")
	if err != nil {
		log.Println(err)
	}
	m.Set(
		&memcache.Item{
			Key:        key,
			Value:      result_json,
			Expiration: 600,
		},
	)
}
开发者ID:cblanck,项目名称:ds-api,代码行数:18,代码来源:api_handler.go

示例5: precreateItemsOrg

func precreateItemsOrg(client *memcache_org.Client) {
	n := *itemsCount / *workersCount
	workerFunc := func(wg *sync.WaitGroup, start int) {
		defer wg.Done()
		item := memcache_org.Item{
			Value: value,
		}
		for i := start; i < start+n; i++ {
			item.Key = fmt.Sprintf("%s_%d", key, i)
			if err := client.Set(&item); err != nil {
				log.Fatalf("Error in Client.Set(): [%s]", err)
			}
		}
	}

	var wg sync.WaitGroup
	defer wg.Wait()
	for i := 0; i < *workersCount; i++ {
		wg.Add(1)
		go workerFunc(&wg, i*n)
	}
}
开发者ID:jjoergensen,项目名称:ybc,代码行数:22,代码来源:main.go

示例6: SavePaste

func SavePaste(paste Paste, ren render.Render, r *http.Request, cf *swift.Connection, mc *memcache.Client) {
	paste.PasteId = genPasteId()
	payload, _ := json.Marshal(paste)
	seconds, err := getTTL(paste.PasteTtl)
	PanicIf(err)
	headers := swift.Headers{}
	now := time.Now()
	pasteIndex := 9999999999 - now.Unix()
	indexKey := fmt.Sprintf("cfpaste-%d", pasteIndex)
	headers["x-object-meta-pastetype"] = paste.PasteType
	headers["x-object-meta-pasteid"] = paste.PasteId
	headers["x-object-meta-pasteindex"] = fmt.Sprintf("%d", pasteIndex)
	if seconds != 0 {
		headers["x-delete-after"] = fmt.Sprintf("%d", seconds)
	}
	buf := bytes.NewBuffer(payload)
	_, err = cf.ObjectPut("go-cfpaste", paste.PasteId, buf, true, "", "application/json; charset=utf-8", headers)
	PanicIf(err)
	// gholt's listing index hack so that he can spy on pastes
	_, err = cf.ObjectPut("go-cfpaste", indexKey, bytes.NewBuffer([]byte("")), true, "", "application/json; charset=utf-8", headers)
	PanicIf(err)
	mc.Set(&memcache.Item{Key: paste.PasteId, Value: payload})
	ren.JSON(200, map[string]interface{}{"pasteid": paste.PasteId})
}
开发者ID:sasimpson,项目名称:cfpaste,代码行数:24,代码来源:cfpaste.go


注:本文中的github.com/bradfitz/gomemcache/memcache.Client.Set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。