定制 danfekete/sequential 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

danfekete/sequential

Composer 安装命令:

composer require danfekete/sequential

包简介

Sequential ID generator

README 文档

README

This library is the successor of the SeqDB engine. The whole purpose of this library is to enable the generation of truly sequential IDs into buckets even when running parallel.

There are times when you need to make sure that when sequentially generating the IDs there are no gaps or repetitions.

Installation

$ composer require danfekete/sequential

Usage

Framework agnostic

You don't need an underlying framework to use this library.

$data = new SQLite();
$seq = new Sequential($data);
$bucket = new Bucket($userID);
$nextID = $seq->generate($bucket);

With Laravel 5.2+

After installing with composer run

$ php artisan vendor:publish --provider=danfekete\Sequential\SequentialServiceProvider

After this, you should see the sequential.php in your config directory. Make the neccessary adjustments (however it also works out of the box).

In your config/app.php add the following:

'providers' => [
  // ...
  danfekete\Sequential\SequentialServiceProvider::class,
  // ...
];

'aliases' => [
  // ...
  'Sequential' =>  danfekete\Sequential\SequentialFacade::class,
  // ...
];

To generate an ID:

$bucket = new Bucket($userID);
$nextID = Sequential::generate($bucket);

Configuration

When using Laravel, the configuration is done in the sequential.php file, otherwise it is done in the constructor.

  • dataProvider (in constructor) - the data object that implements the DataProdvider interface, more on data providers later
  • data_provider_class (in laravel config) - the fully qualified name of the class that implements the DataProvider interface
  • sharedMutex - if true, then the mutex is shared with every bucket, meaning that only a single ID generation takes place at each given moment regardless of the bucket. Otherwise every bucket can run ID generation simultaneously which is the default behaviour.
  • incrementBy - the amount to increment by when generating a new ID

Data providers

The data providers implement the DataProvider interface. The interface has three methods that must be implemented:

  • getLastID(Bucket $bucket) - returns the last ID generated for the given bucket
  • store(Bucket $bucket, $value) - store the value for the bucket
  • reset(Bucket $bucket) - reset the bucket value to 0

You can use the default SQLite data provider or you can roll your own with any kind of advanced of logic. Buckets can contain any amount of data that can be used to query the last ID.

Distributed use

One of the hardest part of sequential ID generation is distributed use. To enable this, there is a specialized version of the main class called DistributedSequential which uses the RedLock DLM algorithm from Redis. You'll need one more Redis servers to use and also the Predis library.

$c1 = new Predis\Client('tcp://10.0.0.1:6379');
$c2 = new Predis\Client('tcp://10.0.0.2:6379');
$data = new SQLite();
$seq = new DistributedSequential([$c1, $c2], $data);
$bucket = new Bucket($userID);
$nextID = $seq->generate($bucket);

danfekete/sequential 适用场景与选型建议

danfekete/sequential 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 08 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-08-15