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


Golang Client.Get方法代码示例

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


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

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

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

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


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