Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
/ raftkv Public archive

A simple distributed key-value store by using hashicorp/raft

License

Notifications You must be signed in to change notification settings

keisku/raftkv

Repository files navigation

raftkv

This repository holds a simple leader-followers key-value store by using hashicorp/raft. raftkv provides gRPC and HTTP APIs. Please take a look API Reference.

Usage

Run containers

docker compose up

Validation

Set a key-value to a leader.

curl -XPOST 'localhost:50002/v1/set' \
--data-raw '{
    "key": "programming_language",
    "value": "golang"
}'

Get a value from a follower. You will get "golang" from followers. It means a leader propagates the value to followers.

curl -XGET 'localhost:50102/v1/get/programming_language'
curl -XGET 'localhost:50202/v1/get/programming_language'

Delete a key-value. You will get "not found" errors from followers.

curl -XDELETE 'localhost:50002/v1/delete/programming_language'
curl -XGET 'localhost:50102/v1/get/programming_language'
curl -XGET 'localhost:50202/v1/get/programming_language'
{"code":5, "message":"not found", "details":[]}
{"code":5, "message":"not found", "details":[]}

If you try to set or delete a key-value to a follower, you will get an error. localhost:50102 is an address for a follower at this time and you can replace it with localhost:50201 too.

See the docker-compose.yaml in detail.

curl -XPOST 'localhost:50102/v1/set' \
--data-raw '{
    "key": "programming_language",
    "value": "golang"
}'
curl -XDELETE 'localhost:50102/v1/delete/programming_language'
{"code":13, "message":"non-leader can't set key=programming_language, value=golang", "details":[]}
{"code":13, "message":"non-leader can't delete a value associated to programming_language", "details":[]}

Releases

No releases published

Packages

No packages published