本文整理匯總了Golang中github.com/valyala/ybc/bindings/go/ybc.Cacher.NewSetTxn方法的典型用法代碼示例。如果您正苦於以下問題:Golang Cacher.NewSetTxn方法的具體用法?Golang Cacher.NewSetTxn怎麽用?Golang Cacher.NewSetTxn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/valyala/ybc/bindings/go/ybc.Cacher
的用法示例。
在下文中一共展示了Cacher.NewSetTxn方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setToCache
func setToCache(cache ybc.Cacher, key []byte, flags uint32, expiration time.Duration, size int) *ybc.SetTxn {
size += binary.Size(&flags)
txn, err := cache.NewSetTxn(key, size, expiration)
if err != nil {
log.Printf("Error in Cache.NewSetTxn() for key=[%s], size=[%d], expiration=[%s]: [%s]", key, size, expiration, err)
return nil
}
binaryWrite(txn, &flags, "flags")
return txn
}
示例2: cSetToCache
func cSetToCache(cache ybc.Cacher, key []byte, size int, flags uint32, expiration time.Duration, etag uint64, validateTtl uint32) *ybc.SetTxn {
size += binary.Size(&etag) + binary.Size(&validateTtl) + binary.Size(&flags)
txn, err := cache.NewSetTxn(key, size, expiration)
if err != nil {
log.Printf("Error in Cache.NewSetTxn() for key=[%s], size=[%d], expiration=[%s]: [%s]", key, size, expiration, err)
return nil
}
binaryWrite(txn, &etag, "etag")
binaryWrite(txn, &validateTtl, "validateTtl")
binaryWrite(txn, &flags, "flags")
return txn
}
示例3: writeItemMetadata
func writeItemMetadata(cache ybc.Cacher, key []byte, size int, ttl time.Duration, etag uint64, validateTtl uint32, flags uint32) *ybc.SetTxn {
validateExpiration64 := uint64(time.Now().Add(time.Duration(validateTtl) * time.Millisecond).UnixNano())
size += binary.Size(&etag) + binary.Size(&validateTtl) + binary.Size(flags) + binary.Size(&validateExpiration64)
txn, err := cache.NewSetTxn(key, size, ttl)
if err != nil {
log.Printf("Unexpected error in Cache.NewSetTxn(size=%d): [%s]", size, err)
return nil
}
binaryWrite(txn, &etag, "etag")
binaryWrite(txn, &validateTtl, "validateTtl")
binaryWrite(txn, &flags, "flags")
binaryWrite(txn, &validateExpiration64, "validateExpiration")
return txn
}
示例4: startSetTxn
func startSetTxn(cache ybc.Cacher, key []byte, flags uint32, expiration time.Duration, size int) *ybc.SetTxn {
casid := getCasid()
size += casidSize + flagsSize
txn, err := cache.NewSetTxn(key, size, expiration)
if err != nil {
log.Printf("Error in Cache.NewSetTxn() for key=[%s], size=[%d], expiration=[%s]: [%s]", key, size, expiration, err)
return nil
}
var buf [casidSize + flagsSize]byte
binary.LittleEndian.PutUint64(buf[:casidSize], casid)
binary.LittleEndian.PutUint32(buf[casidSize:], flags)
n, err := txn.Write(buf[:])
if err != nil {
log.Fatalf("Error in SetTxn.Write(): [%s]", err)
}
if n != len(buf) {
log.Fatalf("Unexpected result returned from SetTxn.Write(): %d. Expected %d", n, len(buf))
}
return txn
}
示例5: writeItemMetadata
func writeItemMetadata(cache ybc.Cacher, key []byte, size int, casid uint64, flags, validateTtl uint32) *ybc.SetTxn {
validateExpiration64 := uint64(time.Now().Add(time.Duration(validateTtl) * time.Millisecond).UnixNano())
size += metadataSize
txn, err := cache.NewSetTxn(key, size, ybc.MaxTtl)
if err != nil {
log.Printf("Unexpected error in Cache.NewSetTxn(size=%d): [%s]", size, err)
return nil
}
var buf [metadataSize]byte
binary.LittleEndian.PutUint64(buf[:casidSize], casid)
binary.LittleEndian.PutUint32(buf[casidSize:], flags)
binary.LittleEndian.PutUint32(buf[casidSize+flagsSize:], validateTtl)
binary.LittleEndian.PutUint64(buf[casidSize+flagsSize+validateTtlSize:], validateExpiration64)
n, err := txn.Write(buf[:])
if err != nil {
log.Fatalf("Error in SetTxn.Write(): [%s]", err)
}
if n != len(buf) {
log.Fatalf("Unexpected result returned from SetTxn.Write(): %d. Expected %d", n, len(buf))
}
return txn
}