本文整理汇总了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
}