proto

package
v0.0.0-...-70491fa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultProto = "redis"

Functions

func DumpProtos

func DumpProtos() (s string)

func RegisterProto

func RegisterProto(name string, f func() Proto) interface{}

Types

type Proto

type Proto interface {
	MarshalRequest(command string, args ...interface{}) ([]byte, error)
	UnmarshalRequest([]byte) (*C.Command, int, error)

	MarshalResponse(*C.Command) []byte
	UnmarshalResponse(buf []byte) (*Reply, int, error)

	MarshalError(error) []byte
}
var GProto Proto

func CreateProto

func CreateProto(name string) Proto

type RedisProto

type RedisProto struct {
}

func (*RedisProto) MarshalError

func (this *RedisProto) MarshalError(e error) []byte

func (*RedisProto) MarshalRequest

func (this *RedisProto) MarshalRequest(command string, args ...interface{}) ([]byte, error)

func (*RedisProto) MarshalResponse

func (this *RedisProto) MarshalResponse(c *C.Command) []byte

func (*RedisProto) UnmarshalRequest

func (this *RedisProto) UnmarshalRequest(buf []byte) (*C.Command, int, error)

func (*RedisProto) UnmarshalResponse

func (this *RedisProto) UnmarshalResponse(buf []byte) (*Reply, int, error)

type Reply

type Reply struct {
	Resp  []string
	Error error
}

type SimpleProto

type SimpleProto struct {
}

一个不能包含空格、换行符,每行一条命令的简单字符协议, 可以用telnet交互

Request:

set a 1\n
get a\n

Response: (+表示请求成功, -表示有error)

+OK\n
+1\n
-Key not exists\n

func (*SimpleProto) MarshalError

func (this *SimpleProto) MarshalError(e error) []byte

func (*SimpleProto) MarshalRequest

func (this *SimpleProto) MarshalRequest(command string, args ...interface{}) ([]byte, error)

func (*SimpleProto) MarshalResponse

func (this *SimpleProto) MarshalResponse(c *C.Command) []byte

func (*SimpleProto) UnmarshalRequest

func (this *SimpleProto) UnmarshalRequest(buf []byte) (*C.Command, int, error)

func (*SimpleProto) UnmarshalResponse

func (this *SimpleProto) UnmarshalResponse(buf []byte) (*Reply, int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL