本文整理匯總了Golang中github.com/dustin/gomemcached.MCRequest.Size方法的典型用法代碼示例。如果您正苦於以下問題:Golang MCRequest.Size方法的具體用法?Golang MCRequest.Size怎麽用?Golang MCRequest.Size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dustin/gomemcached.MCRequest
的用法示例。
在下文中一共展示了MCRequest.Size方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestTransmitReq
func TestTransmitReq(t *testing.T) {
b := bytes.NewBuffer([]byte{})
buf := bufio.NewWriter(b)
req := gomemcached.MCRequest{
Opcode: gomemcached.SET,
Cas: 938424885,
Opaque: 7242,
VBucket: 824,
Extras: []byte{},
Key: []byte("somekey"),
Body: []byte("somevalue"),
}
// Verify nil transmit is OK
_, err := transmitRequest(nil, &req)
if err != errNoConn {
t.Errorf("Expected errNoConn with no conn, got %v", err)
}
_, err = transmitRequest(buf, &req)
if err != nil {
t.Fatalf("Error transmitting request: %v", err)
}
buf.Flush()
expected := []byte{
gomemcached.REQ_MAGIC, byte(gomemcached.SET),
0x0, 0x7, // length of key
0x0, // extra length
0x0, // reserved
0x3, 0x38, // vbucket
0x0, 0x0, 0x0, 0x10, // Length of value
0x0, 0x0, 0x1c, 0x4a, // opaque
0x0, 0x0, 0x0, 0x0, 0x37, 0xef, 0x3a, 0x35, // CAS
's', 'o', 'm', 'e', 'k', 'e', 'y',
's', 'o', 'm', 'e', 'v', 'a', 'l', 'u', 'e'}
if len(b.Bytes()) != req.Size() {
t.Fatalf("Expected %v bytes, got %v", req.Size(),
len(b.Bytes()))
}
if !reflect.DeepEqual(b.Bytes(), expected) {
t.Fatalf("Expected:\n%#v\n -- got -- \n%#v",
expected, b.Bytes())
}
}
示例2: BenchmarkTransmitReqNull
func BenchmarkTransmitReqNull(b *testing.B) {
req := gomemcached.MCRequest{
Opcode: gomemcached.SET,
Cas: 938424885,
Opaque: 7242,
VBucket: 824,
Extras: []byte{},
Key: []byte("somekey"),
Body: []byte("somevalue"),
}
b.SetBytes(int64(req.Size()))
for i := 0; i < b.N; i++ {
err := transmitRequest(ioutil.Discard, &req)
if err != nil {
b.Fatalf("Error transmitting request: %v", err)
}
}
}
示例3: BenchmarkTransmitReqLarge
func BenchmarkTransmitReqLarge(b *testing.B) {
bout := bytes.NewBuffer([]byte{})
req := gomemcached.MCRequest{
Opcode: gomemcached.SET,
Cas: 938424885,
Opaque: 7242,
VBucket: 824,
Extras: []byte{},
Key: []byte("somekey"),
Body: make([]byte, 24*1024),
}
b.SetBytes(int64(req.Size()))
for i := 0; i < b.N; i++ {
bout.Reset()
buf := bufio.NewWriterSize(bout, req.Size()*2)
err := transmitRequest(buf, &req)
if err != nil {
b.Fatalf("Error transmitting request: %v", err)
}
}
}