Documentation
¶
Overview ¶
Package resp implements the Redis serialization protocol, versions 2 and 3. Spec: https://redis.io/docs/latest/develop/reference/protocol-spec/
Index ¶
- Constants
- Variables
- func Append(b []byte, v Value, proto int) []byte
- func AppendCommand(b []byte, args []string) []byte
- func FormatFloat(f float64) string
- func SplitInline(line string) ([]string, error)
- type ProtocolError
- type Reader
- type Type
- type Value
- func Array(vs ...Value) Value
- func Bool(b bool) Value
- func Bulk(s string) Value
- func Bytes(b []byte) Value
- func Double(f float64) Value
- func Err(msg string) Value
- func Errf(format string, args ...any) Value
- func Int(n int64) Value
- func Invalidate(keys []string) Value
- func Map(kv ...Value) Value
- func Multi(vs ...Value) Value
- func None() Value
- func Null() Value
- func NullArray() Value
- func Push(vs ...Value) Value
- func SetOf(vs ...Value) Value
- func Simple(s string) Value
- func StringSet(ss []string) Value
- func Strings(ss []string) Value
- type Writer
Constants ¶
const ( MaxBulkLen = 512 << 20 // 512 MB, same as Redis MaxArrayLen = 1 << 20 )
Variables ¶
var OK = Simple("OK")
Functions ¶
func AppendCommand ¶
AppendCommand appends args encoded as a RESP array of bulk strings.
func FormatFloat ¶
FormatFloat formats a double the way Redis does in RESP2 replies.
func SplitInline ¶
SplitInline splits an inline command line, honouring "double" and 'single' quotes and \n \t \xHH escapes inside double quotes, like redis-cli.
Types ¶
type ProtocolError ¶
type ProtocolError struct{ Msg string }
ProtocolError means the peer sent bytes that are not valid RESP. The connection should be closed after replying.
func (*ProtocolError) Error ¶
func (e *ProtocolError) Error() string
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
func (*Reader) Buffered ¶
Buffered reports bytes already received but not parsed. The server uses it to batch replies of pipelined commands into one flush.
func (*Reader) ReadCommand ¶
ReadCommand reads one client command: either a RESP array of bulk strings or an inline command ("SET a 1\r\n", as typed in telnet).
type Type ¶
type Type byte
const ( TypeSimple Type = '+' TypeError Type = '-' TypeInteger Type = ':' TypeBulk Type = '$' TypeArray Type = '*' // RESP3 types. When talking to a RESP2 client they are down-converted. TypeNull Type = '_' TypeBool Type = '#' TypeDouble Type = ',' TypeMap Type = '%' TypeSet Type = '~' TypePush Type = '>' )
type Value ¶
type Value struct {
Type Type
Str string // simple, error, bulk
Int int64 // integer
Float float64 // double
Bool bool // bool
Elems []Value // array, set, push; map stores key, value, key, value...
// contains filtered or unexported fields
}
Value is any RESP value. Which fields are used depends on Type.
func Err ¶
Err returns an error reply. msg should start with an error code such as "ERR" or "WRONGTYPE"; if it doesn't, "ERR " is added.
func Invalidate ¶
Invalidate builds the push message for client-side caching. A nil keys slice means "flush everything" (sent after FLUSHALL).
type Writer ¶
type Writer struct {
Proto int
// contains filtered or unexported fields
}
Writer encodes values for one connection. Proto is 2 or 3.
func (*Writer) WriteCommand ¶
WriteCommand encodes a command as an array of bulk strings (client side).