Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/ raftdb Public

The raftdb implements a simple distributed key-value database, using the raft distributed consensus protocol.

License

Notifications You must be signed in to change notification settings

hslam/raftdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

63 Commits

Repository files navigation

raftdb

The raftdb implements a simple distributed key-value database, using the raft distributed consensus protocol.

Get started

Install

go get github.com/hslam/raftdb

Build

go build -o raftdb main.go

Three nodes

./raftdb -h=localhost -p=7001 -c=8001 -f=9001 -path=./raftdb.1 \
-members=localhost:9001,localhost:9002,localhost:9003
./raftdb -h=localhost -p=7002 -c=8002 -f=9002 -path=./raftdb.2 \
-members=localhost:9001,localhost:9002,localhost:9003
./raftdb -h=localhost -p=7003 -c=8003 -f=9003 -path=./raftdb.3 \
-members=localhost:9001,localhost:9002,localhost:9003
HTTP SET
curl -XPOST http://localhost:7001/db/foo -d 'bar'
HTTP GET
curl http://localhost:7001/db/foo
Client example
package main
import (
	"fmt"
	"github.com/hslam/raftdb/node"
)
func main() {
	client := node.NewClient("localhost:8001", "localhost:8002", "localhost:8003")
	key := "foo"
	value := "Hello World"
	if ok := client.Set(key, value); !ok {
		panic("set failed")
	}
	if result, ok := client.LeaseReadGet(key); ok && result != value {
		panic(result)
	}
	if result, ok := client.ReadIndexGet(key); ok {
		fmt.Println(result)
	}
}
Output
Hello World

Running on a three nodes cluster.

Write

write-qps write-p99

Read Index

read-qps read-p99

License

This package is licensed under a MIT license (Copyright (c) 2019 Meng Huang)

Author

raftdb was written by Meng Huang.

About

The raftdb implements a simple distributed key-value database, using the raft distributed consensus protocol.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /