本文整理汇总了Golang中github.com/valyala/ybc/bindings/go/ybc.Item.Seek方法的典型用法代码示例。如果您正苦于以下问题:Golang Item.Seek方法的具体用法?Golang Item.Seek怎么用?Golang Item.Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/valyala/ybc/bindings/go/ybc.Item
的用法示例。
在下文中一共展示了Item.Seek方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
}
示例2: 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)
}
}
示例3: 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
}