Wener Site

ulid

约 1 分钟阅读
  • ulid/specGitHubulid/speculid/spec - Universally Unique Lexicographically Sortable Identifier · 例如 · 128bit/16byte - 编码后 26 字符 · timestamp 48bits/6byte + 随机 80bits/10byte笔记:ulid - Universally Unique Lexicographically Sortable Identifier
  • 例如 01ARZ3NDEKTSV4RRFFQ69G5FAV
  • 128bit/16byte - 编码后 26 字符
    • timestamp 48bits/6byte + 随机 80bits/10byte
    • Crockford base32 - 5 bit/char
    • ttttttttttrrrrrrrrrrrrrrrr - t 时间戳, r 随机
    • 时间戳保留到 毫秒
  • 可排序 - 单调递增 - Monotonicity 保证同 ms 内递增
    • 有些实现不一定能保证 - 因为需要状态
    • 如果已经有 时间 信息可直接用于生成 ULID
      • 例如 create_at 列, 创建时间, 一个能标识消息且不会变的时间
  • 大小写无关 - Crockford base32
    • encode 为大写
    • decode 接受大写和小写 - ulid/spec#3GitHub Issueulid/spec#3
    • 大多实现使用 大写 - 但个人倾向小写
  • 无特殊字符 - URL 安全 - 0123456789ABCDEFGHJKMNPQRSTVWXYZ
  • pksunkara/pgx_ulidGitHubpksunkara/pgx_ulidulid/spec - Universally Unique Lexicographically Sortable Identifier · 例如 · 128bit/16byte - 编码后 26 字符 · timestamp 48bits/6byte + 随机 80bits/10byte笔记:ulid
  • ULID 使用 base32 无关大小 - 大多实现使用 大写 - 个人喜欢小写

关联信息

反向链接和本文引用的外部资料。

References

GitHub

3 条
最近更新commit 587932dEdit

On this page