jack

package module
v0.0.0-...-748d515 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2015 License: GPL-2.0 Imports: 6 Imported by: 0

README

Jack

Build Status GoDoc

screenshot

What is Jack?

Jack is a proof-of-concept concurrent key-value server. It supports get, set, publish, subscribe, and delete

The underlying data structure is MetaStore, which is an abstraction over a string map that divides the key-space into buckets for finer lock resolution.

Installation

You can use the Go tool to install the library and dependencies:

export GOPATH=<where you store your Go code>
go get -u github.com/tristanwietsma/jack

The project currently ships with the server, jackd, and a command line interface, jack-cli. Since the Go tool doesn't like multiple build targets in the same project, you need to build them separately:

cd $GOPATH/src/github.com/tristanwietsma/jack
make

The 'make' will build both jackd and jack-cli, as well as move them to $GOCODE/bin.

Usage

To start the server, run jackd:

$ jackd
2013/10/02 15:26:25 created storage with 1000 buckets
2013/10/02 15:26:25 server started on port 2000
...

To start the command-line tool:

jack > help
  GET key [key ...]
  SET key value
  DEL key [key ...]
  PUB key value
  SUB key [key ...]
  QUIT

$ jack-cli
jack> set key123 val567
jack> 1
jack> get key123
jack> key123 := val567
jack> pub key123 765lav
jack> 1
jack> sub key123
...

The commands are all three characters and not case sensitive. The following should be self-explanatory:

jack> set <key> <value>

jack> get <key> [<key> ...] // supports multiple keys

jack> pub <key> <value>

jack> del <key> [<key> ...] // supports multiple keys

jack> sub <key> [<key> ...] // supports multiple keys

Documentation

Index

Constants

View Source
const (
	// EOM denotes the end of a message
	EOM = byte(0)

	// SEP denotes a delimitor between message units
	SEP = byte(30)

	// GET denotes a get-value-at-key command
	GET = byte('g')

	// SET denotes a set-key-to-value command
	SET = byte('s')

	// DEL denotes a delete-key command
	DEL = byte('d')

	// PUB denotes a publish command
	PUB = byte('P')

	// SUB denotes a subscribe command
	SUB = byte('S')

	// SUCCESS denotes a successful client command
	SUCCESS = byte('1')

	// FAIL denotes a failed client command
	FAIL = byte('0')
)

Variables

View Source
var COMMANDS = []byte{GET, DEL, SUB, SET, PUB}

COMMANDS is a list of all valid commands. The order is important: commands with index less than 3 (GET, DEL, SUB) require one additional argument (a key). Commands with index greater than or equal to 3 (SET, PUB) require two arguments (key, value). The index is used in Parse.

Functions

func StartServer

func StartServer(port uint, buckets uint)

StartServer starts up a listened at 127.0.0.1:<port> with a key space distributed over a given number of buckets.

Types

type Connection

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

The Connection struct defines an individual client connection.

func NewConnection

func NewConnection(address string, port uint) (*Connection, error)

NewConnection returns a connection to a given address and port number.

func (*Connection) Close

func (sc *Connection) Close() error

Close closes a connection.

func (*Connection) Delete

func (sc *Connection) Delete(key string) string

Delete removes a key-value pair from the database.

func (*Connection) Get

func (sc *Connection) Get(key string) string

Get returns the value associated with a given key.

func (*Connection) Publish

func (sc *Connection) Publish(key, value string) string

Publish sets a value to a key and triggers a subscriber update.

func (*Connection) Set

func (sc *Connection) Set(key, value string) string

Set assigns a value to a key.

func (*Connection) Subscribe

func (sc *Connection) Subscribe(key string, recv chan<- string)

Subscribe added a channel to the subscription list on a key.

type ConnectionPool

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

The ConnectionPool struct maintains a finite number of connections for use on client-side.

func NewConnectionPool

func NewConnectionPool(address string, port, size uint) *ConnectionPool

NewConnectionPool constructs a ConnectionPool for a given address, port number, and pool size.

func (*ConnectionPool) Connect

func (cp *ConnectionPool) Connect() (*Connection, error)

Connect gets a connection from the pool

func (*ConnectionPool) Free

func (cp *ConnectionPool) Free(c *Connection) error

Free sends a connection back to the pool

type Message

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

Message is the server-side object representation of a client command.

func NewDeleteMessage

func NewDeleteMessage(key string) *Message

NewDeleteMessage constructs a conforming 'del' message

func NewGetMessage

func NewGetMessage(key string) *Message

NewGetMessage constructs a conforming 'get' message

func NewPublishMessage

func NewPublishMessage(key, value string) *Message

NewPublishMessage constructs a conforming 'pub' message

func NewSetMessage

func NewSetMessage(key, value string) *Message

NewSetMessage constructs a conforming 'set' message

func NewSubscribeMessage

func NewSubscribeMessage(key string) *Message

NewSubscribeMessage constructs a conforming 'sub' message

func Parse

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

Parse accepts an incoming byte buffer and returns a Message (and error if malformed).

func (*Message) Bytes

func (c *Message) Bytes() []byte

Bytes returns a byte slice representation of Message per protocol.

type ProtocolError

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

ProtocolError is the error type for a malformed message.

func (ProtocolError) Error

func (e ProtocolError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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