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