client

package
v0.0.0-...-0108d89 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 16 Imported by: 0

README

Tile38 Client

Build Status GoDoc

Tile38 Client is a Go client for Tile38.

THIS LIBRARY IS DEPRECATED

Please use the redigo client library instead. If you need JSON output with Redigo then call:

conn.Do("OUTPUT", "JSON")

Documentation

Index

Examples

Constants

View Source
const LiveJSON = `{"ok":true,"live":true}`

LiveJSON is the value returned when a connection goes "live".

View Source
const MaxMessageSize = 0x1FFFFFFF // 536,870,911 bytes

MaxMessageSize is maximum accepted message size

Variables

This section is empty.

Functions

func WriteHTTP

func WriteHTTP(conn net.Conn, data []byte) error

WriteHTTP writes an http message to the connection and closes the connection.

func WriteMessage

func WriteMessage(w io.Writer, message []byte) error

WriteMessage write a message to an io.Writer

func WriteWebSocket

func WriteWebSocket(conn net.Conn, data []byte) error

WriteWebSocket writes a websocket message.

Types

type Conn

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

Conn represents a connection to a tile38 server.

func Dial

func Dial(addr string) (*Conn, error)

Dial connects to a tile38 server.

Example
conn, err := Dial("localhost:9851")
if err != nil {
	log.Fatal(err)
}
defer conn.Close()
resp, err := conn.Do("set fleet truck1 point 33.5123 -112.2693")
if err != nil {
	log.Fatal(err)
}
fmt.Println(string(resp))
Output:

func DialTimeout

func DialTimeout(addr string, timeout time.Duration) (*Conn, error)

DialTimeout connects to a tile38 server with a timeout.

func (*Conn) Close

func (conn *Conn) Close() error

Close will close a connection.

func (*Conn) Do

func (conn *Conn) Do(command string) ([]byte, error)

Do sends a command to the server and returns the received reply.

func (*Conn) ReadMessage

func (conn *Conn) ReadMessage() (message []byte, err error)

ReadMessage returns the next message. Used when reading live connections

func (*Conn) Reader

func (conn *Conn) Reader() io.Reader

Reader returns the underlying reader.

func (*Conn) Server

func (conn *Conn) Server() (ServerStats, error)

Server returns tile38 server statistics.

func (*Conn) SetDeadline

func (conn *Conn) SetDeadline(t time.Time) error

SetDeadline sets the connection deadline for reads and writes.

func (*Conn) SetReadDeadline

func (conn *Conn) SetReadDeadline(t time.Time) error

SetDeadline sets the connection deadline for reads.

func (*Conn) SetWriteDeadline

func (conn *Conn) SetWriteDeadline(t time.Time) error

SetDeadline sets the connection deadline for writes.

type Pool

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

Pool represents a pool of tile38 connections.

func DialPool

func DialPool(addr string) (*Pool, error)

DialPool creates a new pool with 5 initial connections to the specified tile38 server.

Example
pool, err := DialPool("localhost:9851")
if err != nil {
	log.Fatal(err)
}
defer pool.Close()

// We'll set a point in a background routine
go func() {
	conn, err := pool.Get() // get a conn from the pool
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close() // return the conn to the pool
	_, err = conn.Do("set fleet truck1 point 33.5123 -112.2693")
	if err != nil {
		log.Fatal(err)
	}
}()
time.Sleep(time.Second / 2) // wait a moment

// Retrieve the point we just set.
go func() {
	conn, err := pool.Get() // get a conn from the pool
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close() // return the conn to the pool
	resp, err := conn.Do("get fleet truck1 point")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(resp))
}()
time.Sleep(time.Second / 2) // wait a moment
Output:

func (*Pool) Close

func (pool *Pool) Close() error

Close releases the resources used by the pool.

func (*Pool) Get

func (pool *Pool) Get() (*Conn, error)

Get borrows a connection. When the connection closes, the application returns it to the pool.

type Proto

type Proto int

Proto is the protocol value.

const (
	Native    Proto = 0 // native protocol
	Telnet    Proto = 1 // telnet protocol
	HTTP      Proto = 2 // http protocol
	WebSocket Proto = 3 // websocket protocol
)

func ReadMessage

func ReadMessage(rd *bufio.Reader, wr io.Writer) (message []byte, proto Proto, auth string, err error)

ReadMessage read the next message from a bufio Reader.

type ServerStats

type ServerStats struct {
	Standard
	Stats struct {
		ServerID       string `json:"id"`
		Following      string `json:"following"`
		AOFSize        int    `json:"aof_size"`
		NumCollections int    `json:"num_collections"`
		InMemorySize   int    `json:"in_memory_size"`
		NumPoints      int    `json:"num_points"`
		NumObjects     int    `json:"num_objects"`
		HeapSize       int    `json:"heap_size"`
		AvgItemSize    int    `json:"avg_item_size"`
		PointerSize    int    `json:"pointer_size"`
	} `json:"stats"`
}

ServerStats represents tile38 server statistics.

type Standard

type Standard struct {
	OK      bool   `json:"ok"`
	Err     string `json:"err"`
	Elapsed string `json:"elapsed"`
}

Standard represents a standard tile38 message.

Jump to

Keyboard shortcuts

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