ExCuid2 (ex_cuid2 v0.9.1)
CUID2 (Collision-Resistant Unique Identifiers) generator in Elixir.
This implementation follows the CUID2 standard and generates safe, horizontally scalable IDs, ideal for use as primary keys in databases.
Features:
- Prefix with a random letter.
- Timestamp in milliseconds.
- Atomic counter to prevent collisions in the same millisecond.
- Cryptographically secure entropy.
- Process fingerprint to ensure uniqueness across nodes.
Summary
Functions
Defines how this module should be supervised. This allows it to be added directly to a supervision tree.
Generates a CUID2 with the default length (24 characters).
Generates a CUID2 with a specific length (between 24 and 32).
Validates whether a string matches the CUID2 format.
Starts the counter agent.
Functions
Defines how this module should be supervised. This allows it to be added directly to a supervision tree.
Generates a CUID2 with the default length (24 characters).
Examples
iex> ExCuid2.generate() |> String.length()
24
Generates a CUID2 with a specific length (between 24 and 32).
Examples
iex> ExCuid2.generate(32) |> String.length()
32
Validates whether a string matches the CUID2 format.
Examples
iex> ExCuid2.is_valid?("t4p35j2w2fiyqrec00pjxd7b")
true
iex> ExCuid2.is_valid?("123-abc")
false
Starts the counter agent.
It should be added to the supervision tree in application.ex
.