當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Cacher.NewSetTxn方法代碼示例

本文整理匯總了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
}
開發者ID:inthecloud247,項目名稱:ybc,代碼行數:10,代碼來源:server.go

示例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
}
開發者ID:inthecloud247,項目名稱:ybc,代碼行數:12,代碼來源:server.go

示例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
}
開發者ID:inthecloud247,項目名稱:ybc,代碼行數:17,代碼來源:caching_client.go

示例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
}
開發者ID:rjmcguire,項目名稱:ybc,代碼行數:21,代碼來源:server.go

示例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
}
開發者ID:kangkot,項目名稱:ybc,代碼行數:24,代碼來源:caching_client.go


注:本文中的github.com/valyala/ybc/bindings/go/ybc.Cacher.NewSetTxn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。