tourze/doctrine-snowflake-bundle

0.0.6 2025-04-25 09:02 UTC

This package is auto-updated.

Last update: 2025-04-27 10:14:22 UTC


README

Latest Version Build Status Quality Score Total Downloads

A Snowflake ID generator bundle for Symfony, providing distributed unique ID generation for Doctrine entities.

English | 中文

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.