• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang memcache.Client类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: GetPaste

func GetPaste(params martini.Params, ren render.Render, r *http.Request, cf *swift.Connection, mc *memcache.Client) {
	cachedPaste, err := mc.Get(params["pasteid"])
	format := params["format"]
	if err != nil {
		log.Println(err)
	}
	var paste Paste
	paste.PasteId = params["pasteid"]
	if cachedPaste == nil {
		log.Println("Asking swift for ", params["pasteid"])
		cfPaste, err := cf.ObjectGetBytes("go-cfpaste", params["pasteid"])
		if err != nil {
			if err.Error() == "Object Not Found" {
				ren.HTML(404, "404", paste)
				return
			} else {
				log.Println(err)
				ren.Error(500)
				return
			}
		}
		err = json.Unmarshal(cfPaste, &paste)
		PanicIf(err)
	} else {
		log.Println("Cache hit for ", params["pasteid"])
		err = json.Unmarshal(cachedPaste.Value, &paste)
		PanicIf(err)
	}
	if format == "json" {
		ren.JSON(200, paste)
	} else {
		ren.HTML(200, "paste", paste)
	}
	return
}
开发者ID:sasimpson,项目名称:cfpaste,代码行数:35,代码来源:cfpaste.go


示例2: SessionGet

// 获取 Session, 如果找不到返回 frontend.ErrNotFound.
func SessionGet(token *SessionToken) (*Session, error) {
	if token == nil {
		return nil, errors.New("nil SessionToken")
	}

	var (
		memcacheClient  *memcache.Client
		memcacheItemKey string
	)
	if token.Authenticated {
		memcacheClient = mc.Client()
		memcacheItemKey = mc.SessionCacheKey(token.SessionId)
	} else {
		memcacheClient = secondarymc.Client()
		memcacheItemKey = secondarymc.SessionCacheKey(token.SessionId)
	}

	item, err := memcacheClient.Get(memcacheItemKey)
	if err != nil {
		if err == memcache.ErrCacheMiss {
			err = frontend.ErrNotFound
		}
		return nil, err
	}

	var ss Session
	if err = json.Unmarshal(item.Value, &ss); err != nil {
		return nil, err
	}
	return &ss, nil
}
开发者ID:jack0888,项目名称:go-user,代码行数:32,代码来源:session.go


示例3: 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


示例4: 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


示例5: workerGetMissOrg

func workerGetMissOrg(client *memcache_org.Client, wg *sync.WaitGroup, ch <-chan int, stats *Stats) {
	defer wg.Done()

	for _ = range ch {
		n := rand.Intn(*itemsCount)
		keyStr := fmt.Sprintf("miss_%s_%d", key, n)
		startTime := time.Now()
		if _, err := client.Get(keyStr); err != memcache_org.ErrCacheMiss {
			stats.errorsCount++
			continue
		}
		stats.cacheMissCount++
		updateResponseTimeHistogram(stats, startTime)
	}
}
开发者ID:jjoergensen,项目名称:ybc,代码行数:15,代码来源:main.go


示例6: initQueue

func initQueue() {
	var mc *memcache.Client
	conn := utils.Addrcat(host, port)
	mc = memcache.New(conn)

	err := mc.Add(&memcache.Item{Key: topicName, Value: []byte{}})
	if err != nil {
		log.Printf("add error: %v", err)
	}

	fullLineName := topicName + "/" + lineName
	err = mc.Add(&memcache.Item{Key: fullLineName, Value: []byte{}})
	if err != nil {
		log.Printf("add error: %v", err)
	}
}
开发者ID:henser123,项目名称:uq,代码行数:16,代码来源:mc_bench.go


示例7: 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


示例8: 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


示例9: GetCachedRequest

// Fetches a previously cached API request from memcached, or returns false if
// none exists. Values should only have been set using the CacheSetRequest
// method, and so should be value JSON consisting of a result encapsulated by
// an ApiResult struct.
func GetCachedRequest(memcache *memcache.Client, key string) (bool, []byte) {
	// Try and retrieve the serialized data
	cached_json, err := memcache.Get(key)
	if err != nil {
		// Errors are cache misses
		return false, nil
	}
	return true, cached_json.Value
}
开发者ID:cblanck,项目名称:ds-api,代码行数:13,代码来源:api_handler.go


示例10: getTestSingle

func getTestSingle(ch chan bool, cn, n int) {
	var mc *memcache.Client
	conn := utils.Addrcat(host, port)
	key := topicName + "/" + lineName
	keys := []string{key, "id"}
	mc = memcache.New(conn)
	for i := 0; i < n; i++ {
		start := time.Now()
		items, err := mc.GetMulti(keys)
		if err != nil {
			log.Printf("get error: c%d %v", cn, err)
		} else {
			end := time.Now()
			duration := end.Sub(start).Seconds()
			id := string(items["id"].Value)
			log.Printf("get succ: %s spend: %.3fms", id, duration*1000)
		}
	}
	ch <- true
}
开发者ID:henser123,项目名称:uq,代码行数:20,代码来源:mc_bench.go


示例11: 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


示例12: 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类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang memcache.Item类代码示例发布时间:2022-05-24
下一篇:
Golang memcache.New函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap