resp

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

resp implements redis RESP @see https://redis.io/topics/protocol

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidType            = errors.New("resp: invalid type")
	ErrNumberBuffer           = errors.New("resp: invalid number buffer")
	ErrUnexpectedNumberPrefix = errors.New("resp: unexpected number prefix")
	ErrNumberOfArguments      = errors.New("resp: invalid number of arguments")
	ErrLengthOfArgument       = errors.New("resp: invalid length of argument")
)
View Source
var ErrNumberRange = errors.New("invalid number range")
View Source
var ErrNumberSyntax = errors.New("invalid number syntax")

Functions

This section is empty.

Types

type Command

type Command struct {
	Request *Value
}

Command represents a command that using resp

func NewCommand

func NewCommand() *Command

NewCommand creates a command

func (*Command) Arg

func (cmd *Command) Arg(i int) string

Arg returns ith argument

func (*Command) Is

func (cmd *Command) Is(name string) bool

Is reports whether the command name is `name`

func (*Command) NArg

func (cmd *Command) NArg() int

NArg returns number of arguments

func (*Command) Name

func (cmd *Command) Name() string

Name returns name of command

type Reader

type Reader interface {
	io.Reader
	io.ByteReader

	// ReadLine tries to return a single line, not including the end-of-line bytes.
	ReadLine() (line []byte, isPrefix bool, err error)
}

Reader used to read resp content

type Type

type Type byte

Type of content

const (
	StringType  Type = '+'
	ErrorType   Type = '-'
	IntegerType Type = ':'
	BytesType   Type = '$'
	ArrayType   Type = '*'

	None Type = ' '
)

func (Type) Byte

func (t Type) Byte() byte

Byte of type

func (Type) String

func (t Type) String() string

type Value

type Value struct {
	Type Type
	// contains filtered or unexported fields
}

Value of resp

func NewValue

func NewValue() *Value

NewValue creates a value

func (*Value) Append

func (v *Value) Append(typ Type, value []byte) (appended *Value)

Append appends value to elements of array

func (*Value) AppendNil

func (v *Value) AppendNil()

AppendNil appends nil to elements of array

func (*Value) Bool

func (v *Value) Bool() (bool, error)

Bool returns parsed boolean value

func (*Value) Elements

func (v *Value) Elements() []*Value

Elements returns elements of array

func (*Value) Float

func (v *Value) Float() (float64, error)

Float returns parsed float value

func (*Value) Int64

func (v *Value) Int64() (int64, error)

Int64 returns parsed integer value

func (*Value) IsNil

func (v *Value) IsNil() bool

IsNil reports whether ther value is nil

func (*Value) OK

func (v *Value) OK() bool

OK reports whether the value is OK

func (*Value) ReadFrom

func (v *Value) ReadFrom(r Reader) error

ReadFrom reads value from reader

func (*Value) Reset

func (v *Value) Reset() *Value

Reset resets the value

func (*Value) Set

func (v *Value) Set(x any) error

Set sets the value from interface

func (*Value) SetArray

func (v *Value) SetArray(len int) *Value

SetArray sets the value as an array

func (*Value) SetBytes

func (v *Value) SetBytes(value []byte) *Value

SetBytes sets the value as a Bytes

func (*Value) SetError

func (v *Value) SetError(err error) *Value

SetError sets the value as an error

func (*Value) SetInteger

func (v *Value) SetInteger(i int64) *Value

SetInteger sets the value as an integer

func (*Value) SetNil

func (v *Value) SetNil() *Value

SetNil sets the value as nil

func (*Value) SetString

func (v *Value) SetString(value string) *Value

SetString sets the value as a string

func (*Value) String

func (v *Value) String() string

String returns marshaled string

func (*Value) Value

func (v *Value) Value() []byte

Value returns content of value

func (*Value) WriteTo

func (v *Value) WriteTo(w io.Writer) (int, error)

WriteTo writes marshaled content to w

Jump to

Keyboard shortcuts

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