tourze / doctrine-snowflake-bundle
雪花ID增强
Installs: 2 175
Dependents: 11
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- doctrine/common: ^3.5
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^2.20 || ^3.0
- doctrine/persistence: ^3.1 || ^4
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-kernel: ^6.4
- symfony/property-access: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/bundle-dependency: 0.0.*
- tourze/doctrine-entity-checker-bundle: ~0.0.8
- tourze/symfony-snowflake-bundle: 0.0.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
Suggests
- ext-redis: *
README
A Snowflake ID generator bundle for Symfony, providing distributed unique ID generation for Doctrine entities.
Features
- Based on godruoyi/php-snowflake
- Auto-generate Snowflake IDs for Doctrine entity properties
- Optional Redis sequence resolver to reduce ID duplication under high concurrency
- Custom ID prefix and length limit
- WorkerId auto-generated by hostname, supporting distributed deployment
Installation
composer require tourze/doctrine-snowflake-bundle
Quick Start
Add a Snowflake ID to your entity:
use Tourze\DoctrineSnowflakeBundle\Attribute\SnowflakeColumn; class YourEntity { #[SnowflakeColumn(prefix: 'ORDER_', length: 32)] private string $id; // ... other properties and methods }
Configuration
Redis Sequence Resolver (optional)
To use Redis for sequence resolution and reduce ID duplication:
# config/packages/snc_redis.yaml snc_redis: clients: default: type: phpredis alias: default dsn: redis://localhost
Requirements
- PHP 8.1 or newer
- Symfony 6.4 or newer
- Doctrine Bundle 2.13 or newer
License
MIT License
Contributing
Contributions are welcome! Please submit issues or pull requests.
Changelog
See Releases for version history.