本文整理汇总了Golang中github.com/bradfitz/gomemcache/memcache.Item类的典型用法代码示例。如果您正苦于以下问题:Golang Item类的具体用法?Golang Item怎么用?Golang Item使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Item类的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: Update
//Update captcha info
func (store *MCStore) Update(key string, captcha *CaptchaInfo) bool {
item := new(memcache.Item)
item.Key = MC_KEY_PREFIX + key
item.Value = store.encodeValue(captcha)
err := store.mc.Set(item)
if nil != err {
log.Printf("update key in memcache err:%s", err)
return false
} else {
return true
}
}
开发者ID:whidbey,项目名称:gocaptcha,代码行数:15,代码来源:mcstore.go
示例3: 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
示例4: Put
// Put put value to memcache.
func (rc *Cache) Put(key string, val interface{}, timeout time.Duration) error {
if rc.conn == nil {
if err := rc.connectInit(); err != nil {
return err
}
}
item := memcache.Item{Key: key, Expiration: int32(timeout / time.Second)}
if v, ok := val.([]byte); ok {
item.Value = v
} else if str, ok := val.(string); ok {
item.Value = []byte(str)
} else {
return errors.New("val only support string and []byte")
}
return rc.conn.Set(&item)
}
开发者ID:xxoommd,项目名称:beego,代码行数:17,代码来源:memcache.go
示例5: Add
//Add captcha info and get the auto generated key
func (store *MCStore) Add(captcha *CaptchaInfo) string {
key := fmt.Sprintf("%s%s%x", captcha.Text, randStr(20), time.Now().UnixNano())
key = hex.EncodeToString(md5.New().Sum([]byte(key)))
key = key[:32]
item := new(memcache.Item)
item.Key = MC_KEY_PREFIX + key
item.Value = store.encodeValue(captcha)
err := store.mc.Add(item)
if nil != err {
log.Printf("add key in memcache err:%s", err)
}
return key
}
开发者ID:whidbey,项目名称:gocaptcha,代码行数:19,代码来源:mcstore.go
示例6: 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
注:本文中的github.com/bradfitz/gomemcache/memcache.Item类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论