raftCache 基于raft的分布式缓存demo raftCache

letterbeezps2022-05-15 19:39:18 • 2488 次点击    
这是一个分享于 2022-05-15 19:39:18 的项目,其中的信息可能已经有所发展或是发生改变。

raftCache

一个用来学习raft协议的demo,使用raft协议来构建一个分布式缓存,项目参考了hraftd

调试代码

leader 启动初始化节点node0

cd /cmd
go run main.go -id node0 node0

follower 加入多个follower node1 & node2

go run main.go -id node1 -haddr :11001 -raddr :12001 -join :11000 node1

go run main.go -id node2 -haddr :11002 -raddr :12002 -join :11000 node2

得到三个副本

├── test_dbnode0
│   ├── raft-log.db
│   ├── raft-stable.db
│   └── snapshots
├── test_dbnode1
│   ├── raft-log.db
│   ├── raft-stable.db
│   └── snapshots
└── test_dbnode2
    ├── raft-log.db
    ├── raft-stable.db
    └── snapshots

调试API

只能对leader节点发起请求

POST 127.0.0.1:11000/v1/cache/key

{
    "value": "testNode0Value1"
}

DELETE 127.0.0.1:11000/v1/cache/key

可以最任意一个节点发起请求

GET 127.0.0.1:11000/v1/cache/key 127.0.0.1:11001/v1/cache/key 127.0.0.1:11002/v1/cache/key

{
    "key": "key",
    "value": {
        "value": "testNode0Value1"
    }
}

A demo for learning raft protocolRead More

Latest commit to the master branch on 5-15-2022
Download as zip
授权协议:
开发语言:
go 查看源码»
2488 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传