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


Golang MCRequest.Bytes方法代碼示例

本文整理匯總了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()

}
開發者ID:lynseyahaynes,項目名稱:mbserver,代碼行數:26,代碼來源:mbclient.go

示例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
}
開發者ID:lmarlow,項目名稱:gomemcached,代碼行數:11,代碼來源:transport.go

示例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()

}
開發者ID:lynseyahaynes,項目名稱:mbserver,代碼行數:24,代碼來源:mbclient.go

示例4: transmitRequest

func transmitRequest(o io.Writer, req *gomemcached.MCRequest) (err error) {
	_, err = o.Write(req.Bytes())
	return
}
開發者ID:seacoastboy,項目名稱:gomemcached,代碼行數:4,代碼來源:mc.go


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