本文整理汇总了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
}
示例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)
}
}
}
示例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
}
示例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)
}
}
示例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
}