https://github.com/hslam/raftdb
The raftdb implements a simple distributed key-value database, using the raft distributed consensus protocol.
https://github.com/hslam/raftdb
distributed go golang kvdb raft
Last synced: about 1 year ago
JSON representation
The raftdb implements a simple distributed key-value database, using the raft distributed consensus protocol.
- Host: GitHub
- URL: https://github.com/hslam/raftdb
- Owner: hslam
- License: mit
- Created: 2019-12-04T17:15:17.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-17T14:21:49.000Z (about 3 years ago)
- Last Synced: 2024-06-20T12:05:50.132Z (about 2 years ago)
- Topics: distributed, go, golang, kvdb, raft
- Language: Go
- Homepage:
- Size: 69.3 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# raftdb
The raftdb implements a simple distributed key-value database, using the [raft](https://github.com/hslam/raft "raft") distributed consensus protocol.
## Get started
### Install
```
go get github.com/hslam/raftdb
```
### Build
```
go build -o raftdb main.go
```
#### Three nodes
```sh
./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
```go
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
```
### [Benchmark](https://github.com/hslam/raft-benchmark "raft-benchmark")
Running on a three nodes cluster.
##### Write


##### Read Index


## License
This package is licensed under a MIT license (Copyright (c) 2019 Meng Huang)
## Author
raftdb was written by Meng Huang.