/raft-example

Minimal hashicorp/raft example

Primary LanguageGoMIT LicenseMIT

Minimal hashicorp/raft example

Example:

Terminal 1:

$ go build
$ ./raft-example --node-id node1 --raft-port 2222 --http-port 8222

Terminal 2:

$ go build
$ ./raft-example --node-id node2 --raft-port 2223 --http-port 8223

Terminal 3, tell 1 to have 2 follow it:

$ curl 'localhost:8222/join?followerAddr=localhost:2223&followerId=node2'

Terminal 3, now add a key:

$ curl -X POST 'localhost:8222/set' -d '{"key": "x", "value": "23"}' -H 'content-type: application/json'

Terminal 3, now get the key from either server:

$ curl 'localhost:8222/get?key=x'
{"data":"23"}
$ curl 'localhost:8223/get?key=x'
{"data":"23"}

References: