Stability | experimental |
---|---|
Maintainer | [email protected] |
Safe Haskell | None |
Data.Snowflake
Description
This generates unique(guaranteed) identifiers build from time stamp,
counter(inside same millisecond) and node id - if you wish to generate
ids across several nodes. Identifiers are convertible to Integer
values which are monotonically increasing with respect to time.
- data SnowflakeConfig = SnowflakeConfig {
- confTimeBits :: !Int
- confCountBits :: !Int
- confNodeBits :: !Int
- data Snowflake
- data SnowflakeGen
- newSnowflakeGen :: SnowflakeConfig -> Integer -> IO SnowflakeGen
- nextSnowflake :: SnowflakeGen -> IO Snowflake
- defaultConfig :: SnowflakeConfig
- snowflakeToInteger :: Snowflake -> Integer
Documentation
data SnowflakeConfig Source
Configuration that specifies how much bits are used for each part of the id. There are no limits to total bit sum.
Constructors
SnowflakeConfig | |
Fields
|
Instances
Generated identifier. Can be converted to Integer
.
data SnowflakeGen Source
Generator which contains needed state. You should use newSnowflakeGen
to create instances.
newSnowflakeGen :: SnowflakeConfig -> Integer -> IO SnowflakeGenSource
Create a new generator. Takes a configuration and node id.
nextSnowflake :: SnowflakeGen -> IO SnowflakeSource
Generates next id. The bread and butter. See module description for details.
defaultConfig :: SnowflakeConfigSource
Default configuration using 40 bits for time, 16 for count and 8 for node id.
snowflakeToInteger :: Snowflake -> IntegerSource
Converts an identifier to an integer with respect to configuration used to generate it.