Git Product home page Git Product logo

m2's Introduction

m2

m2 is a simple http key/value cache system based on hashicorp/raft.


Install

go get github.com/qichengzx/m2

Create Cluster

Start first node

./m2 --node_id 1 --port 8001 --raft_port 18001

then, start second node

./m2 --node_id 2 --port 8002 --raft_port 18002
curl -d 'nodeid=2&addr=127.0.0.1:18002' http://localhost:8001/raft/join

Key/Value Api

HTTP API

  • /set - set key&value
  • /get - get value
  • /del - del key

Query params expected are key and val

# set
curl "http://localhost:8001/set?key=foo&val=bar"
# or use post method 
# curl -d "key=foo&val=bar" http://localhost:8001/set
# output:ok

# get
curl "http://localhost:8002/get?key=foo"
# output:bar

# del
curl "http://localhost:8001/del?key=foo"
# output:ok

Raft Api

HTTP API

  • /raft/join - join raft cluster
  • /raft/leave - leave raft cluster
  • /raft/status - get raft node status
# join
curl "http://localhost:8001/raft/join?nodeid=2&addr=127.0.0.1:18002"
# or use post method 
# curl -d "nodeid=2&addr=127.0.0.1:18002" http://localhost:8001/raft/join
# output:ok

# leave
curl "http://localhost:8001/raft/leave?nodeid=2&addr=127.0.0.1:18002"
# output:removed successfully

# node status
curl "http://localhost:8001/raft/status"
# output:
{
    "applied_index": "2",
    "commit_index": "2",
    "fsm_pending": "0",
    "last_contact": "0",
    "last_log_index": "2",
    "last_log_term": "2",
    "last_snapshot_index": "0",
    "last_snapshot_term": "0",
    "latest_configuration": "[{Suffrage:Voter ID:1 Address:127.0.0.1:18001}]",
    "latest_configuration_index": "0",
    "num_peers": "0",
    "protocol_version": "3",
    "protocol_version_max": "3",
    "protocol_version_min": "0",
    "snapshot_version_max": "1",
    "snapshot_version_min": "0",
    "state": "Leader",
    "term": "2"
}

Storage

m2 use badger-db as storage

License

m2 is under the MIT license. See the LICENSE file for details.

m2's People

Contributors

qichengzx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

xiaomiazi520

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.