proto

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

a simple and high-performance library for parsing and encoding redis protocal and redis inline command

Index

Constants

View Source
const (
	T_SimpleString = '+'
	T_Error        = '-'
	T_Integer      = ':'
	T_BulkString   = '$'
	T_Array        = '*'
)

Variables

View Source
var (
	CRLF = []byte{'\r', '\n'}
)

Functions

func ReadDataBytes

func ReadDataBytes(r *bufio.Reader, obj *Object) error

read data bytes reads a full RESP object bytes

Types

type Command

type Command struct {
	Args []string //Args[0] is the command name
}

Command

redis supports two kinds of Command: (Inline Command) and (Array With BulkString)

func NewCommand

func NewCommand(args ...string) (*Command, error)

make a new command like terminal

cmd, err := NewCommand("get", "username")

func ReadCommand

func ReadCommand(r *bufio.Reader) (*Command, error)

read a command from bufio.Reader

func (Command) Format

func (c Command) Format() []byte

Foramat a command into ArrayWithBulkString

func (Command) Integer

func (c Command) Integer(index int) (ret int64)

get command.Args[index] in int64. return 0 if it isn't numberic string.

func (Command) Name

func (c Command) Name() string

get the command name

func (Command) Value

func (c Command) Value(index int) (ret string)

get command.Args[index] in string

I must change the method name from String to Value, because method named String has specical meaning when working with fmt.Sprintf.

type Data

type Data struct {
	T       byte
	String  []byte
	Integer int64
	Array   []*Data
	IsNil   bool
}

a resp package

func ReadData

func ReadData(r *bufio.Reader) (*Data, error)

get a data from bufio.Reader

func (Data) Format

func (d Data) Format() []byte

format Data into resp string

type Object

type Object struct {
	// contains filtered or unexported fields
}

func NewObject

func NewObject() *Object

func NewObjectFromData

func NewObjectFromData(data *Data) *Object

func (*Object) Append

func (o *Object) Append(buf []byte)

func (*Object) Raw

func (o *Object) Raw() []byte

Jump to

Keyboard shortcuts

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