本文整理匯總了Golang中github.com/dustin/gomemcached.MCRequest.Bytes方法的典型用法代碼示例。如果您正苦於以下問題:Golang MCRequest.Bytes方法的具體用法?Golang MCRequest.Bytes怎麽用?Golang MCRequest.Bytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dustin/gomemcached.MCRequest
的用法示例。
在下文中一共展示了MCRequest.Bytes方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: sendGet
func sendGet(key string) {
req := gomemcached.MCRequest{
Opcode: gomemcached.GET,
Cas: 938424885,
Opaque: 7242,
VBucket: 824,
Extras: []byte{},
Key: []byte(key),
Body: []byte{},
}
conn, _ := net.Dial("tcp", "localhost:9955")
conn.Write(req.Bytes())
res := gomemcached.MCResponse{}
_, err := res.Receive(bufio.NewReader(conn), nil)
if err != nil {
fmt.Println("Error: ", err.Error())
}
fmt.Println(res.String())
value := string(res.Body[:len(res.Body)])
fmt.Println(value)
conn.Close()
}
示例2: transmitRequest
func transmitRequest(o io.Writer, req *gomemcached.MCRequest) (err error) {
if len(req.Body) < 128 {
_, err = o.Write(req.Bytes())
} else {
_, err = o.Write(req.HeaderBytes())
if err == nil && len(req.Body) > 0 {
_, err = o.Write(req.Body)
}
}
return
}
示例3: sendUnknownCommand
func sendUnknownCommand() {
req := gomemcached.MCRequest{
Opcode: gomemcached.ADD,
Cas: 938424885,
Opaque: 7242,
VBucket: 824,
Extras: []byte{},
Key: []byte("key"),
Body: []byte("somevalue"),
}
conn, _ := net.Dial("tcp", "localhost:9955")
conn.Write(req.Bytes())
res := gomemcached.MCResponse{}
_, err := res.Receive(bufio.NewReader(conn), nil)
if err != nil {
fmt.Println("Error: ", err.Error())
}
fmt.Println(res.String())
conn.Close()
}
示例4: transmitRequest
func transmitRequest(o io.Writer, req *gomemcached.MCRequest) (err error) {
_, err = o.Write(req.Bytes())
return
}