leaves

Crates.ioleaves
lib.rsleaves
version0.5.0
sourcesrc
created_at2019-11-24 16:34:42.467338
updated_at2020-08-20 09:07:46.257279
descriptionDistributed ID Allocator
homepage
repositoryhttps://github.com/songzhi/leaves
max_upload_size
id184004
size112,219
李冬冬 (songzhi)

documentation

README

Leaves: Distributed ID Generation Service

This is a unofficial port of Leaf.

🏠 Homepage

Latest version

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)

Commit count: 50

cargo fmt