respgo

package module
v0.0.0-...-20b1acb Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2017 License: MIT Imports: 7 Imported by: 0

README

respgo

A Go implementation of REdis Serialization Protocol (RESP).

Build Status Coverage Status License GoDoc

Installation

go get github.com/teambition/respgo

Examples

str := string(respgo.EncodeString("OK"))
fmt.Println(str)
// +OK\r\n

reader := bufio.NewReader(strings.NewReader("+OK\r\n"))
result, _ := respgo.Decode(reader)
fmt.Println(result)
// OK

str = string(respgo.EncodeError("Error message"))
fmt.Println(str)
// -Error message\r\n

reader = bufio.NewReader(strings.NewReader("-Error message\r\n"))
result, _ = respgo.Decode(reader)
fmt.Println(result)
// Error message

str = string(respgo.EncodeInt(1000))
fmt.Println(str)
// :1000\r\n

reader = bufio.NewReader(strings.NewReader(":1000\r\n"))
result, _ = respgo.Decode(reader)
fmt.Println(result)
// 1000

str = string(respgo.EncodeBulkString("foobar"))
fmt.Println(str)
// $6\r\nfoobar\r\n

reader = bufio.NewReader(strings.NewReader("$6\r\nfoobar\r\n"))
result, _ = respgo.Decode(reader)
fmt.Println(result)
// foobar

str = string(respgo.EncodeNull())
fmt.Println(str)
// $-1\r\n

reader = bufio.NewReader(strings.NewReader("$-1\r\n"))
result, _ = respgo.Decode(reader)
fmt.Println(result)
// <nil>

str = string(respgo.EncodeArray([][]byte{
  respgo.EncodeBulkString("foo"),
  respgo.EncodeBulkString("bar")}))
fmt.Println(str)
// *2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n

reader = bufio.NewReader(strings.NewReader("*2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n"))
result, _ = respgo.Decode(reader)
fmt.Println(result)
// [foo bar]

str = string(respgo.EncodeNullArray())
fmt.Println(str)
// *-1\r\n

reader = bufio.NewReader(strings.NewReader("*-1\r\n"))
result, _ = respgo.Decode(reader)
fmt.Println(result)
// <nil>

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(reader *bufio.Reader) (result interface{}, err error)

Decode decode from reader

func EncodeArray

func EncodeArray(s [][]byte) []byte

EncodeArray encode a slice of byte slice. It accepts the results of other encode method including itself. For example: EncodeArray([][]byte{EncodeInt(1), EncodeNull()})

func EncodeBulkString

func EncodeBulkString(s string) []byte

EncodeBulkString encodes a bulk string

func EncodeError

func EncodeError(s string) []byte

EncodeError encodes a error string

func EncodeInt

func EncodeInt(s int64) []byte

EncodeInt encodes an int

func EncodeNull

func EncodeNull() []byte

EncodeNull encodes null value

func EncodeNullArray

func EncodeNullArray() []byte

EncodeNullArray encodes null array

func EncodeString

func EncodeString(s string) []byte

EncodeString encodes a simple string

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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