{"id":19448537,"url":"https://github.com/vnt-dev/raft","last_synced_at":"2025-04-25T02:31:22.467Z","repository":{"id":105577344,"uuid":"320764799","full_name":"vnt-dev/raft","owner":"vnt-dev","description":"使用java基于raft协议实现的kv数据库","archived":false,"fork":false,"pushed_at":"2021-01-16T13:08:07.000Z","size":2645,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-03T15:04:56.945Z","etag":null,"topics":["raft","rocksdb"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vnt-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-12T06:28:46.000Z","updated_at":"2025-03-20T01:13:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"954c1190-1ed0-4969-8f08-b993ad3e49c3","html_url":"https://github.com/vnt-dev/raft","commit_stats":null,"previous_names":["vnt-dev/raft"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnt-dev%2Fraft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnt-dev%2Fraft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnt-dev%2Fraft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnt-dev%2Fraft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vnt-dev","download_url":"https://codeload.github.com/vnt-dev/raft/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250741934,"owners_count":21479702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["raft","rocksdb"],"created_at":"2024-11-10T16:27:25.959Z","updated_at":"2025-04-25T02:31:22.148Z","avatar_url":"https://github.com/vnt-dev.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 使用java基于raft协议实现的kv数据库\n\n## 简介\n 1. 使用java实现的raft协议，在半数以上节点正常时服务可用，系统满足线性一致性；\n 2. 使用netty实现底层通信，利用protobuf进行编解码；\n 3. 使用rocksDB进行日志和状态机的持久化，数据基于磁盘，消耗内存小；\n 4. 使用rocksDB存储状态机快照，对日志落后过多的节点传输快照可以快速恢复数据；\n 5. 主节点请求复制日志的缓冲区会根据并发量动态调配，既能适应高吞吐量场景又能降低单次请求的响应时间；\n 6. 支持简单kv操作，支持过期时间的设置。\n\n## 简单使用\n### 一、搭建服务端集群\n    \n ```\n    #运行jar即可(第一次启动jar会创建默认配置文件以及日志、状态机、快照文件目录，如需更换端口可修改对应配置)\n\n    #本机地址端口\n    ip=127.0.0.1\n    port=8040\n    #所有节点\n    nodes=127.0.0.1:8040,127.0.0.1:8041,127.0.0.1:8042\n```\n### 二、客户端使用\n\n-  配置服务端节点，可以写在配置文件中，也可使用api配置\n```\n  //这里简单使用api进行设置节点\n  PropertiesUtil.setValue(\"nodes\", \"127.0.0.1:8041,127.0.0.1:8042,127.0.0.1:8043\");\n```\n- 同步调用(所有修改操作均支持过期时间的设置)\n```\n    StringKvOperations operations = new StringKvOperations();\n    //设值\n    operations.opsForValue().set(\"test\",\"v1\");\n    //删除\n    operations.opsForValue().delete(\"test\");\n    //设置key，并附带过期时间\n    operations.opsForValue().set(\"test\",\"v1\",1000L);\n    //存在时修改\n    boolean setIfPresent = operations.opsForValue().setIfPresent(\"test\", \"0\");\n    //不存在时修改\n    boolean setIfAbsent = operations.opsForValue().setIfAbsent(\"test\", \"0\");\n    //设置过期时间\n    boolean expire = operations.opsForValue().expire(\"test\", 100L);\n    //获取\n    String testValue = operations.opsForValue().get(\"test\");\n    //自增\n    long incr = operations.opsForValue().incr(\"test\");\n    long incrBy = operations.opsForValue().incrBy(\"test\",10L);\n    //自减\n    long decr = operations.opsForValue().decr(\"test\");\n    //是否存在\n    boolean hasKey = operations.opsForValue().hasKey(\"test\");\n```\n\n- 异步调用（数据操作和同步api一致，增加回调函数即可）\n```\n    StringKvOperations operations = new StringKvOperations();\n    //异步自增\n    operations.opsForValueAsync().incr(\"async\", v -\u003e {\n         //自增成功后调用\n         System.out.println(\"async incr:\"+v)\n   });\n```\n    \n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvnt-dev%2Fraft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvnt-dev%2Fraft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvnt-dev%2Fraft/lists"}