ksuid-tcl

TCL module for K-Sortable Unique Identifiers (KSUIDs). A TCL/C implementation of Segment's KSUID library.

Contact: neophytos (at) gmail (dot) com

ksuid-tcl git repo

Releases

  • v1.0.3 (2024-03-29 - TCL 9 support)

KSUID is for K-Sortable Unique IDentifier. It is a kind of globally unique identifier similar to a UUID, built from the ground-up to be "naturally" sorted by generation timestamp without any special type-aware logic. In short, running a set of KSUIDs through the UNIX sort command will result in a list ordered by generation time.

Some organizations like to prefix KSUIDs with some prefix that denotes the type of the object that the id is used for, e.g. cus_2VB3rZ7VN8syq2WsQDdWt6DdvSi for a customer. As you can see the text representation is copy-and-paste friendly.

set ksuid [::ksuid::generate_ksuid]
# 2VDWAizIu0qTXiApIPdt5yQ9LkT

string length $ksuid
# 27

set parts [::ksuid::ksuid_to_parts $ksuid]
# timestamp 294370989 payload 4e7d497583a45e54c098a51a275ca62d

::ksuid::parts_to_ksuid $parts
# 2VDWAizIu0qTXiApIPdt5yQ9LkT