本文整理匯總了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
}