ordinary/uid 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ordinary/uid

Composer 安装命令:

composer require ordinary/uid

包简介

Library for using and generating universally unique ids.

README 文档

README

Ordinary UID is a simple solution for generating universally unique ids.

Table of Contents

Getting Started

Install using composer.

composer require ordinary/uid

Using the generator

require_once 'vendor/autoload.php';

$randomizer = new \Random\Randomizer(new \Random\Engine\Secure());
$clock = new \Ordinary\Clock\UTCClock();
$generator = new \Ordinary\UID\Generator($clock, $randomizer);

var_dump($generator->generate(4));
var_dump($generator->generateCustom('external-id-1'))

Features

Universally unique

IDs generated are considered to be universally unique with the assumption that no two machines will generate a UID at the exact same time with the exact same random bytes.

Time based

The first part is a hexadecimal representation of the timestamp from which it was created. The second part is also a hexadecimal representation of the fractional time of the timestamp from which it was created

Sortable

With the first two parts being representations of time, UIDs can be easily sorted by creation time, by sorting them by their string value. Additionally, if UID is generated using a custom value for custom bytes, the custom bytes portion will be sortable as well, as long as the custom value would have been sortable.

Custom time precision

  • Time precision can be customized to use millisecond, microsecond, or nanosecond granularity.
  • Microsecond granularity is default (1,000,000 UIDs per second)

Custom unique identifiers

The last part contains bytes converted to a hexadecimal (Max: 15). This can be used to add a custom identifier, or to add additional uniqueness to the ID.

UID Interface Methods

UIDInterface::value()

Get the string value of a UID instance.

UIDInterface::dateTime()

Get a DateTimeImmutable instance of the UID.

UIDInterface::timeSeconds()

Get the timestamp in seconds of the UID.

UIDInterface::timeFraction()

Get the fraction of a second in units determined by the precision.

UIDInterface::timePrecision()

Get the precision used to create the UID.

UIDInterface::custom()

Get the custom bytes of the UID.

UID Generator Methods

Generator::generate(int $customBytes)

Generate an Ordinary UID with a given number of random bytes.

Generator::generateCustom(string $custom)

Generate an Ordinary UID with the given bytes. $custom can be any string as long as the number of bytes is between 1 and 15.

ordinary/uid 适用场景与选型建议

ordinary/uid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 02 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 ordinary/uid 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ordinary/uid 我们能提供哪些服务?
定制开发 / 二次开发

基于 ordinary/uid 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-06