frostflake
Customizable and thread-safe distributed id generator, like twitter's snowflake.
Basic usage for single generator
use ;
use thread;
let generator = new;
Use multi generator by GeneratorPool
use ;
use thread;
// create 10 generators
let pool = new;
Configurations
frostflake is highly configurable.
use ;
let opts = default
.bits // 42bit timestamp, 10bit node, 12bit sequence
.base_ts // base time 2017-01-01T00:00:00Z as milliseonds
.node; // node number
let generator = new;
Also, time function is can be set. If you want to use plain seconds unit instead of millisedond, you can do by this:
use ;
use ;
// use smaller time bits (because this is not milliseconds)
// use larger sequence bits
let opts = default
.base_ts // need this for avoid exceeding time value on smaller bit size
.bits
.base_ts // base time should be second too
.time_fn; // set my time function
let generator = new;
Default configurations
Generator
Options | Default value |
---|---|
bits | 42=timestamp, 10=node, 12=sequence |
base_ts | 1483228800000 (2017-01-01T00:00:00Z as milliseonds) |
node | 0 |
time_fn | return current milliseonds |
GeneratorPool
Almost same as Generator, but GeneratorPool uses pool_id
bit for distinguish each pools.
So default bit widths is:
Options | Default value |
---|---|
bits | 42=timestamp, 4=pool_id, 6=node, 12=sequence |
All other options are same with Generator.