nats-io/nuid

GitHub: nats-io/nuid

NATS 团队开源的高性能唯一标识符生成库,通过加密随机前缀与伪随机递增相结合的方式,以极低的熵消耗实现每秒千万级的 ID 生成。

Stars: 374 | Forks: 45

# NUID [![Apache 2 许可证](https://img.shields.io/badge/License-Apache2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) [![报告卡](https://goreportcard.com/badge/github.com/nats-io/nuid)](https://goreportcard.com/report/github.com/nuid/nuid) [![构建状态](https://static.pigsec.cn/wp-content/uploads/repos/cas/99/993938d8ce5e902ccfb9d6747725c320d855dea3235ed9a304cedf0d94c9321f.svg)](https://github.com/nats-io/nuid/actions) [![发布版本](https://img.shields.io/badge/release-v1.0.1-1eb0fc.svg)](https://github.com/nats-io/nuid/releases/tag/v1.0.1) [![Go 参考](https://pkg.go.dev/badge/github.com/nats-io/nuid.svg)](https://pkg.go.dev/github.com/nats-io/nuid) [![覆盖率状态](https://coveralls.io/repos/github/nats-io/nuid/badge.svg?branch=main)](https://coveralls.io/github/nats-io/nuid?branch=main) 一个高性能的唯一标识符生成器。 ## 安装 使用 `go` 命令: ``` $ go get github.com/nats-io/nuid ``` ## 基本用法 ``` // Utilize the global locked instance nuid := nuid.Next() // Create an instance, these are not locked. n := nuid.New() nuid = n.Next() // Generate a new crypto/rand seeded prefix. // Generally not needed, happens automatically. n.RandomizePrefix() ``` ## 性能 NUID 需要具备极高的生成速度和真正的唯一性,同时还要对熵池友好。 NUID 使用 12 字节的加密生成数据(会消耗熵),以及 10 字节的伪随机 顺序数据,该数据以伪随机增量进行递增。 NUID 字符串的总长度为 22 字节的 base 62 ascii 文本,即 62^22 或 2707803647802660400290261537185326956544 种可能性。 NUID 生成标识符的速度可快至 60ns,即每秒约 1600 万个。我们提供了一个相关的 benchmark,您可以使用它来测试您硬件上的性能。 ## 许可证 除非另有说明,否则 NATS 源文件均遵循在 LICENSE 文件中找到的 Apache 2.0 版本许可证进行分发。
标签:EVTX分析, 日志审计