Juicy

package module
v0.0.0-...-34eddc3 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

README ΒΆ

Juicy 🍸

"It was all a dream, I used to read Word Up! magazine."

-- The Notorious B.I.G.

Juicy is a simple memory key/value database. it use naive_raft to support distributed consistency. It is not finished yet, only partial functions are supported.

INSTALL

go get -u github.com/salamer/Juicy

QUICK START

Client Side


package main

import (
	"fmt"

	client "github.com/salamer/Juicy/client"
)

func main() {
	c := client.NewJuicyClient("localhost", 8080)
	c.Set("helloq", "world")
	c.Set("hahah", "wwww")
	c.Set("aaaa", "zzzz")
	fmt.Println(c.Get("aaaa"))
	fmt.Println(c.Get("helloq"))
	fmt.Println(c.Get("hahah"))
	fmt.Println(c.Delete("hahah"))
	fmt.Println(c.Get("hahah"))
	c.Persist("aaa.txt")
	fmt.Println(c.Empty())
	c.Persist("db.juicy")
	c.Clear()
	fmt.Println(c.Empty())
}

Server Side

Single Node

package main

import (
	"fmt"

	Juicy "github.com/salamer/Juicy"
)

func main() {
	db := Juicy.NewDB("hello", Juicy.SINGLE, Juicy.RaftConf{})
	db.Start()
}


Multi Node

package main

import (
	"fmt"

	Juicy "github.com/salamer/Juicy"
)

const ConfPath = {confpath}      //your node conf json file
const ID = {id}                  //your node id
const Name = {name}              //your node name
const Host = {host}              //your raft node host
const Port = {port}              //your raft node port

func main() {
	db := Juicy.NewDB("hello", Juicy.DISTRIBUTED, Juicy.RaftConf{
		ID:       ID,
		Name:     Name,
		ConfPath: ConfPath,
		Port:     Port,
		Host:     Host,
	})
	db.Start()
}



TODO

  • Compress
  • Better Persist

LICENSE

Copyright Β© 2018 by Aljun

Under Apache license : http://www.apache.org/licenses/

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	SINGLE = iota
	DISTRIBUTED
)
View Source
const Newline = "\n"
View Source
const SEPARATOR = " "
View Source
const SEPARATOR_PLACEHOLER = "\t"

Variables ΒΆ

View Source
var (
	KeyError         = errors.New("key not in database")
	ValueError       = errors.New("Value Error")
	MissCommandError = errors.New("Missing right command")
)

Functions ΒΆ

func Hash ΒΆ

func Hash(s string) int

Types ΒΆ

type DB ΒΆ

type DB struct {
	Tree *rbt.Tree

	Mode int
	// contains filtered or unexported fields
}

func GetDBFromFile ΒΆ

func GetDBFromFile(filename string) *DB

func NewDB ΒΆ

func NewDB(name string, mode int, conf RaftConf, host string, port int) *DB

func (*DB) Clear ΒΆ

func (db *DB) Clear()

func (*DB) CommandRPC ΒΆ

func (db *DB) CommandRPC(ctx context.Context, in *pb.CommandReq) (*pb.CommandResp, error)

func (*DB) Delete ΒΆ

func (db *DB) Delete(key string) error

func (*DB) Empty ΒΆ

func (db *DB) Empty() bool

func (*DB) GetNode ΒΆ

func (db *DB) GetNode(key string) (*Node, error)

func (*DB) GetValue ΒΆ

func (db *DB) GetValue(key string) (string, error)

func (*DB) HaveKey ΒΆ

func (db *DB) HaveKey(key string) (bool, error)

func (*DB) Persist ΒΆ

func (db *DB) Persist(filename string)

func (*DB) SetValue ΒΆ

func (db *DB) SetValue(key string, value string) error

func (*DB) Size ΒΆ

func (db *DB) Size() int

func (*DB) Start ΒΆ

func (db *DB) Start()

type Node ΒΆ

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

func NewNode ΒΆ

func NewNode(key string, value string) *Node

func SafeString ΒΆ

func SafeString(a interface{}) (*Node, error)

type RaftConf ΒΆ

type RaftConf struct {
	ID       int
	Name     string
	ConfPath string
	Port     int
	Host     string
}

Directories ΒΆ

Path Synopsis
Package Juicy is a generated protocol buffer package.
Package Juicy is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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