• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang gomemcached.MCResponse类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/dustin/gomemcached.MCResponse的典型用法代码示例。如果您正苦于以下问题:Golang MCResponse类的具体用法?Golang MCResponse怎么用?Golang MCResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了MCResponse类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: sendAck

func (mc *Client) sendAck(pkt *gomemcached.MCRequest) (int, error) {
	res := gomemcached.MCResponse{
		Opcode: pkt.Opcode,
		Opaque: pkt.Opaque,
		Status: gomemcached.SUCCESS,
	}
	return res.Transmit(mc.conn)
}
开发者ID:mbrukman,项目名称:gomemcached,代码行数:8,代码来源:tap_feed.go


示例3: transmitResponse

func transmitResponse(o io.Writer, res *gomemcached.MCResponse) (err error) {
	if len(res.Body) < 128 {
		_, err = o.Write(res.Bytes())
	} else {
		_, err = o.Write(res.HeaderBytes())
		if err == nil && len(res.Body) > 0 {
			_, err = o.Write(res.Body)
		}
	}
	return
}
开发者ID:mschoch,项目名称:gomemcached,代码行数:11,代码来源:mc_conn_handler.go


示例4: vbRGet

func vbRGet(v *VBucket, w io.Writer, req *gomemcached.MCRequest) (
	res *gomemcached.MCResponse) {
	// From http://code.google.com/p/memcached/wiki/RangeOps
	// Extras field  Bits
	// ------------------
	// End key len	 16
	// Reserved       8
	// Flags          8
	// Max results	 32

	res = &gomemcached.MCResponse{
		Opcode: req.Opcode,
		Cas:    req.Cas,
	}

	extras := make([]byte, 4)

	visitRGetResults := int64(0)
	visitOutgoingValueBytes := int64(0)

	visitor := func(i *item) bool {
		if bytes.Compare(i.key, req.Key) >= 0 {
			// TODO: Need to hide expired items from range scan.
			binary.BigEndian.PutUint32(extras, i.flag)
			r := gomemcached.MCResponse{
				Opcode: req.Opcode,
				Key:    i.key,
				Cas:    i.cas,
				Extras: extras,
				Body:   i.data,
			}
			err := r.Transmit(w)
			if err != nil {
				res = &gomemcached.MCResponse{Fatal: true}
				return false
			}
			visitRGetResults++
			visitOutgoingValueBytes += int64(len(i.data))
		}
		return true
	}

	if err := v.ps.visitItems(req.Key, true, visitor); err != nil {
		res = &gomemcached.MCResponse{Fatal: true}
	}

	atomic.AddInt64(&v.stats.RGets, 1)
	atomic.AddInt64(&v.stats.RGetResults, visitRGetResults)
	atomic.AddInt64(&v.stats.OutgoingValueBytes, visitOutgoingValueBytes)

	return res
}
开发者ID:scottcagno,项目名称:cbgb,代码行数:52,代码来源:vbucket.go


示例5: sendMalformedCommand

func sendMalformedCommand() {
	req := "HERE ARE SOME BYTES TO SEE IF YOUR SERVER CAN HANDLE THEM!"

	conn, _ := net.Dial("tcp", "localhost:9955")

	conn.Write([]byte(req))

	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,代码行数:16,代码来源:mbclient.go


示例6: BenchmarkTransmitResNull

func BenchmarkTransmitResNull(b *testing.B) {
	res := gomemcached.MCResponse{
		Opcode: gomemcached.SET,
		Cas:    938424885,
		Opaque: 7242,
		Status: 824,
		Key:    []byte("somekey"),
		Body:   []byte("somevalue"),
	}

	b.SetBytes(int64(res.Size()))

	for i := 0; i < b.N; i++ {
		err := transmitResponse(ioutil.Discard, &res)
		if err != nil {
			b.Fatalf("Error transmitting request: %v", err)
		}
	}
}
开发者ID:shenoyvvarun,项目名称:gomemcached,代码行数:19,代码来源:server_test.go


示例7: TestTransmitRes

func TestTransmitRes(t *testing.T) {
	b := bytes.NewBuffer([]byte{})
	buf := bufio.NewWriter(b)

	res := gomemcached.MCResponse{
		Opcode: gomemcached.SET,
		Cas:    938424885,
		Opaque: 7242,
		Status: 0x338,
		Extras: []byte{},
		Key:    []byte("somekey"),
		Body:   []byte("somevalue"),
	}

	err := transmitResponse(buf, &res)
	if err != nil {
		t.Fatalf("Error transmitting request: %v", err)
	}

	buf.Flush()

	expected := []byte{
		gomemcached.RES_MAGIC, byte(gomemcached.SET),
		0x0, 0x7, // length of key
		0x0,       // extra length
		0x0,       // reserved
		0x3, 0x38, // Status
		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()) != res.Size() {
		t.Fatalf("Expected %v bytes, got %v", res.Size(),
			len(b.Bytes()))
	}

	if !reflect.DeepEqual(b.Bytes(), expected) {
		t.Fatalf("Expected:\n%#v\n  -- got -- \n%#v",
			expected, b.Bytes())
	}
}
开发者ID:lmarlow,项目名称:gomemcached,代码行数:43,代码来源:server_test.go


示例8: BenchmarkReceive

func BenchmarkReceive(b *testing.B) {
	res := gomemcached.MCResponse{
		Opcode: gomemcached.SET,
		Cas:    938424885,
		Opaque: 7242,
		Status: 824,
		Key:    []byte("somekey"),
		Body:   []byte("somevalue"),
	}

	datum := res.Bytes()
	datum[0] = gomemcached.REQ_MAGIC
	b.SetBytes(int64(len(datum)))

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_, err := ReadPacket(bytes.NewReader(datum))
		if err != nil {
			b.Fatalf("Failed to read: %v", err)
		}
	}
}
开发者ID:mbrukman,项目名称:gomemcached,代码行数:22,代码来源:server_test.go


示例9: BenchmarkTransmitResLarge

func BenchmarkTransmitResLarge(b *testing.B) {
	bout := &bytes.Buffer{}

	res := gomemcached.MCResponse{
		Opcode: gomemcached.SET,
		Cas:    938424885,
		Opaque: 7242,
		Status: 824,
		Key:    []byte("somekey"),
		Body:   make([]byte, 24*1024),
	}

	b.SetBytes(int64(res.Size()))

	for i := 0; i < b.N; i++ {
		bout.Reset()
		buf := bufio.NewWriterSize(bout, res.Size()*2)
		err := transmitResponse(buf, &res)
		if err != nil {
			b.Fatalf("Error transmitting request: %v", err)
		}
	}
}
开发者ID:shenoyvvarun,项目名称:gomemcached,代码行数:23,代码来源:server_test.go


示例10: 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


示例11: notFound

func notFound(req *gomemcached.MCRequest, s *storage) *gomemcached.MCResponse {
	var response gomemcached.MCResponse
	response.Status = gomemcached.UNKNOWN_COMMAND
	return &response
}
开发者ID:mbrukman,项目名称:gomemcached,代码行数:5,代码来源:mc_storage.go


示例12: transmitResponse

func transmitResponse(o io.Writer, res *gomemcached.MCResponse) (err error) {
	return res.Transmit(o)
}
开发者ID:natars,项目名称:gomemcached,代码行数:3,代码来源:mc_conn_handler.go


示例13: transmitResponse

func transmitResponse(s io.Writer, res *gomemcached.MCResponse) error {
	_, err := s.Write(res.Bytes())
	return err
}
开发者ID:seacoastboy,项目名称:gomemcached,代码行数:4,代码来源:mc_conn_handler.go



注:本文中的github.com/dustin/gomemcached.MCResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang randbo.New函数代码示例发布时间:2022-05-23
下一篇:
Golang gomemcached.MCRequest类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap