PHPackages                             phillarmonic/allegro-redis-odm-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. phillarmonic/allegro-redis-odm-bundle

ActiveSymfony-bundle

phillarmonic/allegro-redis-odm-bundle
=====================================

Redis ODM (Object Document Mapper) for Symfony - store and retrieve PHP objects using Redis

1.3.0(10mo ago)57.2k—0%MITPHPPHP &gt;=8.2

Since Mar 26Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/Phillarmonic/allegro-redis-odm-bundle)[ Packagist](https://packagist.org/packages/phillarmonic/allegro-redis-odm-bundle)[ RSS](/packages/phillarmonic-allegro-redis-odm-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (9)Versions (6)Used By (0)

AllegroRedisOdmBundle
=====================

[](#allegroredisodmbundle)

A Symfony bundle providing an Object Document Mapper (ODM) for Redis. This bundle simplifies storing, retrieving, and managing PHP objects in Redis with support for various Redis storage formats, indexing, automated object hydration, and tools for handling large datasets.

Features
--------

[](#features)

- **Simple object persistence** - Store PHP objects directly in Redis.
- **Multiple storage formats** - Store documents as Redis Hashes or JSON.
- **Automatic indexing** - Create and maintain secondary indices (Redis Sets) for fast lookups.
- **Sorted Indices &amp; Range Queries** - Efficiently query numeric or string ranges using Redis Sorted Sets (via `#[SortedIndex]` and `RangeQuery` builder).
- **Repository pattern** - Clean data access through document repositories.
- **Attribute-based mapping** - Define document structure using PHP 8 attributes.
- **TTL support** - Set expiration times for documents and indices.
- **Multiple client support** - Works with both PhpRedis and Predis clients.
- **Optimized for Large Datasets** - Utilizes Redis `SCAN` for key iteration and server-side operations (like `SINTERSTORE`) where appropriate to minimize memory overhead and improve performance.
- **Batch Processing Utilities** - Provides `BatchProcessor` and `BulkOperations` services for efficient handling of large data volumes.
- **Performance Analysis Tools** - Includes `allegro:analyze-performance` command to inspect collection statistics, memory usage, and benchmark common operations.
- **Symfony integration** - Seamlessly integrates with the Symfony framework.

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Symfony 6.0+ or 7.0+
- Redis server
- Either the PHP Redis extension (`ext-redis`) or `predis/predis` package

Installation
------------

[](#installation)

### Step 1: Install the bundle

[](#step-1-install-the-bundle)

```
composer require phillarmonic/allegro-redis-odm-bundle
```

### Step 2: Enable the bundle in your kernel

[](#step-2-enable-the-bundle-in-your-kernel)

```
// config/bundles.php
return [
    // ...
    Phillarmonic\AllegroRedisOdmBundle\AllegroRedisOdmBundle::class => ['all' => true],
];
```

### Step 3: Configure the bundle

[](#step-3-configure-the-bundle)

Create a configuration file at `config/packages/allegro_redis_odm.yaml`:

```
allegro_redis_odm:
    client_type: phpredis  # Options: phpredis, predis
    connection:
        scheme: redis      # Options: redis, rediss (for TLS)
        host: 127.0.0.1
        port: 6379
        database: 0
        # auth: null       # Password if required
        # read_timeout: 0  # In seconds, 0 for no timeout
        # persistent: false
        # options: {}      # Client-specific options, e.g., for Predis SSL: { ssl: { verify_peer: true } }

    # Default storage settings
    default_storage:
        type: hash         # Options: hash, json
        ttl: 0             # Default TTL in seconds (0 = no expiration)

    # Document mappings
    mappings:
        app:
            dir: '%kernel.project_dir%/src/Document' # Directory containing your document classes
            namespace: 'App\Document'                # Base namespace for your document classes
            prefix: 'app'  # Optional global prefix for all Redis keys managed by this mapping
```

Usage
-----

[](#usage)

### Defining Documents

[](#defining-documents)

Create document classes in your project (e.g., in `src/Document/`):

```
