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

Golang ybc.Item类代码示例

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

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



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

示例1: writeGetResponse

func writeGetResponse(w *bufio.Writer, key []byte, item *ybc.Item, shouldWriteCasid bool, scratchBuf *[]byte) bool {
	var casid uint64
	var buf [casidSize + flagsSize]byte
	n, err := item.Read(buf[:])
	if err != nil {
		log.Printf("error when reading item metadata: [%s]", err)
		return false
	}
	if n != len(buf) {
		log.Printf("Unexpected result returned from ybc.Item.Read(): %d. Expected %d", n, len(buf))
		return false
	}
	if shouldWriteCasid {
		casid = binary.LittleEndian.Uint64(buf[:])
	}
	flags := binary.LittleEndian.Uint32(buf[casidSize:])

	size := item.Available()
	if !writeStr(w, strValue) || !writeStr(w, key) || !writeWs(w) ||
		!writeUint32(w, flags, scratchBuf) || !writeWs(w) ||
		!writeInt(w, size, scratchBuf) {
		return false
	}

	if shouldWriteCasid {
		if !writeWs(w) || !writeUint64(w, casid, scratchBuf) {
			return false
		}
	}

	return writeStr(w, strCrLf) && writeItem(w, item, size)
}
开发者ID:rjmcguire,项目名称:ybc,代码行数:32,代码来源:server.go


示例2: writeItem

func writeItem(w *bufio.Writer, item *ybc.Item, size int) bool {
	n, err := item.WriteTo(w)
	if err != nil {
		log.Printf("Error when writing payload with size=[%d] to output stream: [%s]", size, err)
		return false
	}
	if n != int64(size) {
		log.Printf("Invalid length of payload=[%d] written to output stream. Expected [%d]", n, size)
		return false
	}
	return writeCrLf(w)
}
开发者ID:rjmcguire,项目名称:ybc,代码行数:12,代码来源:server.go


示例3: setItemValue

func setItemValue(it *ybc.Item, item *Item) error {
	size := it.Available()
	item.Value = make([]byte, size)
	n, err := it.Read(item.Value)
	if err != nil {
		log.Fatalf("Unexpected error in Item.Read(size=%d): [%s]", size, err)
	}
	if n != size {
		log.Fatalf("Unexpected number of bytes read in Item.Read(size=%d): %d", size, n)
	}
	return nil
}
开发者ID:kangkot,项目名称:ybc,代码行数:12,代码来源:caching_client.go


示例4: updateLocalItem

func updateLocalItem(cache ybc.Cacher, it *ybc.Item, key []byte, casid uint64, flags, validateTtl uint32) {
	size := it.Available()
	defer it.Seek(-int64(size), 2)

	txn := writeItemMetadata(cache, key, size, casid, flags, validateTtl)
	if txn == nil {
		return
	}
	defer txn.Commit()

	n, err := txn.ReadFrom(it)
	if err != nil {
		log.Fatalf("Unexpected error in SetTxn.ReadFrom(size=%d): [%s]", size, err)
	}
	if n != int64(size) {
		log.Fatalf("Unexpected number of bytes copied in SetTxn.ReadFrom(size=%d): %d", size, n)
	}
}
开发者ID:kangkot,项目名称:ybc,代码行数:18,代码来源:caching_client.go


示例5: writeCgetResponse

func writeCgetResponse(w *bufio.Writer, etag uint64, item *ybc.Item, scratchBuf *[]byte) bool {
	var validateTtl, flags uint32
	if err := binaryRead(item, &validateTtl, "validateTtl"); err != nil {
		return false
	}
	if err := binaryRead(item, &flags, "flags"); err != nil {
		return false
	}

	size := item.Available()
	expiration := item.Ttl()
	return writeStr(w, strValue) && writeInt(w, size, scratchBuf) && writeWs(w) &&
		writeUint32(w, flags, scratchBuf) && writeWs(w) &&
		writeExpiration(w, expiration, scratchBuf) && writeWs(w) &&
		writeUint64(w, etag, scratchBuf) && writeWs(w) &&
		writeUint32(w, validateTtl, scratchBuf) && writeCrLf(w) &&
		writeItem(w, item, size)
}
开发者ID:inthecloud247,项目名称:ybc,代码行数:18,代码来源:server.go


示例6: readItemMetadata

func readItemMetadata(it *ybc.Item) (casid uint64, flags uint32, validateExpiration time.Time, validateTtl uint32, ok bool) {
	var buf [metadataSize]byte
	n, err := it.Read(buf[:])
	if err != nil {
		log.Printf("Cannot read metadata for cached item: [%s]", err)
		return
	}
	if n != len(buf) {
		log.Printf("Unexpected result returned from ybc.Item.Read(): %d. Expected %d", n, len(buf))
		return
	}
	casid = binary.LittleEndian.Uint64(buf[:])
	flags = binary.LittleEndian.Uint32(buf[casidSize:])
	validateTtl = binary.LittleEndian.Uint32(buf[casidSize+flagsSize:])
	validateExpiration64 := binary.LittleEndian.Uint64(buf[casidSize+flagsSize+validateTtlSize:])
	validateExpiration = time.Unix(0, int64(validateExpiration64))
	ok = true
	return
}
开发者ID:kangkot,项目名称:ybc,代码行数:19,代码来源:caching_client.go


示例7: writeGetResponse

func writeGetResponse(w *bufio.Writer, key []byte, item *ybc.Item, cas bool, scratchBuf *[]byte) bool {
	var flags uint32
	if err := binaryRead(item, &flags, "flags"); err != nil {
		return false
	}

	size := item.Available()
	if !writeStr(w, strValue) || !writeStr(w, key) || !writeWs(w) ||
		!writeUint32(w, flags, scratchBuf) || !writeWs(w) ||
		!writeInt(w, size, scratchBuf) {
		return false
	}
	if cas {
		if !writeWs(w) || !writeZero(w) {
			return false
		}
	}
	return writeCrLf(w) && writeItem(w, item, size)
}
开发者ID:inthecloud247,项目名称:ybc,代码行数:19,代码来源:server.go


示例8: checkAndUpdateCasid

func checkAndUpdateCasid(item *ybc.Item, casid *uint64) (isModified, ok bool) {
	casidOld := *casid
	var buf [casidSize]byte
	n, err := item.Read(buf[:])
	if err != nil {
		log.Printf("Cannod read casid from item: [%s]", err)
		return
	}
	if n != len(buf) {
		log.Printf("Unexpected result returned from ybc.Item.Read(): %d. Expected %d", n, len(buf))
		return
	}
	*casid = binary.LittleEndian.Uint64(buf[:])

	if _, err := item.Seek(-casidSize, 1); err != nil {
		log.Fatalf("Unexpected error returned from ybc.Item.Seek(%d, 1): [%s]", -casidSize, err)
	}

	isModified = (casidOld != *casid)
	ok = true
	return
}
开发者ID:rjmcguire,项目名称:ybc,代码行数:22,代码来源:server.go


示例9: updateLocalItem

func updateLocalItem(cache ybc.Cacher, it *ybc.Item, item *Item, etag uint64, validateTtl uint32) {
	size := it.Available()
	offset := it.Size() - size
	defer it.Seek(int64(offset), 0)

	txn := writeItemMetadata(cache, item.Key, size, it.Ttl(), etag, validateTtl, item.Flags)
	if txn == nil {
		return
	}
	defer txn.Commit()

	n, err := txn.ReadFrom(it)
	if err != nil {
		log.Fatalf("Unexpected error in SetTxn.ReadFrom(size=%d): [%s]", size, err)
	}
	if n != int64(size) {
		log.Fatalf("Unexpected number of bytes copied in SetTxn.ReadFrom(size=%d): %d", size, n)
	}

}
开发者ID:inthecloud247,项目名称:ybc,代码行数:20,代码来源:caching_client.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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