7 releases (4 breaking)
0.5.0 | Aug 20, 2020 |
---|---|
0.4.0-beta.1 | May 31, 2020 |
0.3.0 | Jan 25, 2020 |
0.2.1 | Jan 15, 2020 |
0.1.1 | Nov 25, 2019 |
#1409 in Asynchronous
21 downloads per month
39KB
938 lines
Leaves: Distributed ID Generation Service
This is a unofficial port of Leaf.
🏠 Homepage
Features
- generate id in segment mode
- generate id in snowflake mode
- mysql
- redis
- postgresql
- sqlite
- mongodb
- runtime-agnostic(tokio or async-std) when using mysql or postgres
- lazy mode: fetch leaf by tag lazily and needs remove it manually
- http server or rpc service(actually just implement it by yourself 😂)
TODO
- performance
- correctness
Example
Enabling the mysql
and runtime-tokio
feature:
use leaves::dao::MySqlLeafDao;
use leaves::{SegmentIDGen, Config, Result};
#[tokio::main]
async main() -> Result<()> {
let dao = Arc::new(MySqlLeafDao::new("mysql://...").await?);
let mut service = SegmentIDGen::new(dao, Config::new());
service.init().await?;
let tag = 1;
for _ in 0..1000 {
println!("{}", service.get(tag).await?);
}
}
Benchmark
1,000,000 IDs in 180ms(local MongoDB with R7 3700X)
Dependencies
~1–22MB
~359K SLoC