resp

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2014 License: MIT Imports: 7 Imported by: 24

Documentation

Overview

This package provides an easy to use interface for creating and parsing messages encoded in the REdis Serialization Protocol (RESP). You can check out more details about the protocol here: http://redis.io/topics/protocol

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteArbitrary

func WriteArbitrary(w io.Writer, m interface{}) error

WriteArbitrary takes in any primitive golang value, or Message, and writes its encoded form to the given io.Writer, inferring types where appropriate.

func WriteArbitraryAsFlattenedStrings added in v0.4.2

func WriteArbitraryAsFlattenedStrings(w io.Writer, m interface{}) error

WriteArbitraryAsFlattenedStrings is similar to WriteArbitrary except that it will encode all types except Array as a BulkStr, converting the argument into a string first as necessary. It will also flatten any embedded arrays into a single long array. This is useful because commands to a redis server must be given as an array of bulk strings. If the argument isn't already in a slice or map it will be wrapped so that it is written as an Array of size one.

Note that if a Message type is found it will *not* be encoded to a BulkStr, but will simply be passed through as whatever type it already represents.

func WriteArbitraryAsString

func WriteArbitraryAsString(w io.Writer, m interface{}) error

WriteArbitraryAsString is similar to WriteArbitraryAsFlattenedString except that it won't flatten any embedded arrays.

func WriteMessage

func WriteMessage(w io.Writer, m *Message) error

WriteMessage takes in the given Message and writes its encoded form to the given io.Writer

Types

type Message

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

func NewMessage

func NewMessage(b []byte) (*Message, error)

NewMessagePParses the given raw message and returns a Message struct representing it

func ReadMessage

func ReadMessage(reader io.Reader) (*Message, error)

ReadMessage attempts to read a message object from the given io.Reader, parse it, and return a Message struct representing it

func (*Message) Array

func (m *Message) Array() ([]*Message, error)

Array returns the Message slice encompassed by this Messsage, assuming the Message is of type Array

func (*Message) Bytes

func (m *Message) Bytes() ([]byte, error)

Bytes returns a byte slice representing the value of the Message. Only valid for a Message of type SimpleStr, Err, and BulkStr. Others will return an error

func (*Message) Err

func (m *Message) Err() (error, error)

Err returns an error representing the value of the Message. Only valid for Err messages

func (*Message) Int

func (m *Message) Int() (int64, error)

Int returns an int64 representing the value of the Message. Only valid for Int messages

func (*Message) Str

func (m *Message) Str() (string, error)

Str is a Convenience method around Bytes which converts the output to a string

type Type

type Type int
const (
	SimpleStr Type = iota
	Err
	Int
	BulkStr
	Array
	Nil
)

Jump to

Keyboard shortcuts

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