2017 © Pedro Peláez
 

library id-generator

ID Generator based on Apc and MySQL

image

flashytime/id-generator

ID Generator based on Apc and MySQL

  • Thursday, May 10, 2018
  • by flashytime
  • Repository
  • 1 Watchers
  • 1 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

ID Generator

ID Generator based on Apc and MySQL which can be used to generate primary key for sharding mysql tables., (*1)

Installation

  • Run the composer require command from your terminal:
composer require flashytime/id-generator
  • Create a mysql table named 'id_generator' with the id_generator.sql:
CREATE TABLE `id_generator` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL COMMENT '名字',
  `current_id` bigint(20) unsigned NOT NULL COMMENT '当前最大ID',
  `step` int(11) unsigned NOT NULL COMMENT '步长',
  `length` int(11) unsigned NOT NULL COMMENT '缓存步长',
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='ID生成器';
  • Copy the id-generator.php file from the config directory to config/id-generator.php

Usage

$idGenerator = new \Flashytime\ApcIdGenerator\IdGenerator($config);
$idGenerator->setTable('id_generator');
$id = $idGenerator->getId('test_name');

Laravel and Lumen

Laravel 5

Add a ServiceProvider to your providers array in config/app.php:, (*2)

'providers' => [

    Flashytime\IdGenerator\Provider\LaravelIdGeneratorServiceProvider::class,

]

Finally, publish the configuration files via php artisan vendor:publish., (*3)

Lumen

For Lumen add the following in your bootstrap/app.php, (*4)

$app->register(Flashytime\IdGenerator\Provider\LumenIdGeneratorServiceProvider::class);

Copy the id-generator.php file from the config directory to config/id-generator.php, (*5)

And also add the following to bootstrap/app.php, (*6)

$app->configure('id-generator');

Usage

app('id-generator')->setTable('id_generator');
$id = app('id-generator')->getId('test_name');

License

MIT, (*7)

The Versions

10/05 2018

dev-master

9999999-dev

ID Generator based on Apc and MySQL

  Sources   Download

MIT

The Requires

  • php >=5.6
  • ext-apcu *

 

The Development Requires

by Avatar flashytime

08/05 2018

v1.0.0

1.0.0.0

ID Generator based on Apc and MySQL

  Sources   Download

MIT

The Requires

  • php >=5.6
  • ext-apcu *

 

The Development Requires

by Avatar flashytime