PHPackages                             twanhaverkamp/event-storage-in-redis-with-php - 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. [Caching](/categories/caching)
4. /
5. twanhaverkamp/event-storage-in-redis-with-php

ActiveLibrary[Caching](/categories/caching)

twanhaverkamp/event-storage-in-redis-with-php
=============================================

Event Storage in Redis with PHP

1.2.0(4mo ago)01MITPHPPHP ^8.3CI passing

Since Feb 13Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/twanhaverkamp/event-storage-in-redis-with-php)[ Packagist](https://packagist.org/packages/twanhaverkamp/event-storage-in-redis-with-php)[ RSS](/packages/twanhaverkamp-event-storage-in-redis-with-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (0)

Event storage in Redis with PHP
===============================

[](#event-storage-in-redis-with-php)

This package is a [Redis](https://redis.io/) implementation for the ["Event Sourcing with PHP"](https://github.com/twanhaverkamp/event-sourcing-with-php) library.

**Table of Contents**

- [Usage](#usage)
    - [Installation](#installation)
    - [Implementation](#implementation)
        - [Connect with Redis](#connect-with-redis)
        - [Event storage](#event-storage)
    - [Dependency injection](#dependency-injection)
        - [Laravel project](#laravel-project)
        - [Symfony project](#symfony-project)

Usage
-----

[](#usage)

### Installation

[](#installation)

**Requirements:**

- PHP 8.3 (or higher)

If you're using [Composer](https://getcomposer.org/) in your project you can run the following command:

```
composer require composer require twanhaverkamp/event-storage-in-redis-with-php:^1.0
```

### Implementation

[](#implementation)

Most PHP frameworks like Symfony and Laravel allows you to register classes as services; If you like, you can register this Event store where you bind it to the EventStoreInterface.

#### Connect with Redis

[](#connect-with-redis)

When constructing the [Event Store](/src/Event/EventStore/Redis.php) you're required to pass an instance of the [Predis client](https://github.com/predis/predis) as first argument and an Event describer instance as second argument.

```
// ...

use Predis\Client as PredisClient;
use TwanHaverkamp\EventSourcingWithPhp\Event\EventDescriber;
use TwanHaverkamp\EventStorageInRedisWithPhp\Event\EventStore;

// ...

$eventStore = new EventStore\Redis(
    new PredisClient([
        'scheme' => 'tcp',
        'host'   => 'http://redis-stack',
        'port'   => 6379,
    ]),
    new EventDescriber\KebabCase(),
);

// ...
```

> An Event describer can be found in the "Event Sourcing with PHP" library, which is automatically installed whenever you install this package. You can create your own Describer if you like; just make sure it implements the EventDescriberInterface, which can also be found in the "Event Sourcing with PHP" library.

#### Event registration

[](#event-registration)

In order for the Event Store to know which type of Events exist, you need to register them in the Event Store:

```
use TwanHaverkamp\EventSourcingWithPhp\Example;
use TwanHaverkamp\EventStorageInRedisWithPhp\Event\EventStore;

EventStore\Redis::register(
    Example\Event\InvoiceWasCreated::class,
    Example\Event\PaymentTransactionWasStarted::class,
    Example\Event\PaymentTransactionWasCompleted::class,
    Example\Event\PaymentTransactionWasCancelled::class,
);
```

> You have to register your Events before actually using the Event Store.

#### Event storage

[](#event-storage)

When you pass an Aggregate to the `save` function it loops over its Events and for every Event it will create a new [String](https://redis.io/docs/latest/develop/data-types/strings/) where the key is constructed with the AggregateRootId, the recordedAt value as timestamp (including microseconds) and Event name.

Every Aggregate get its own [Sorted Set](https://redis.io/docs/latest/develop/data-types/sorted-sets/), where the Event keys are stored. *With this solution we don't need to perform slow and complex queries.*

### Dependency injection

[](#dependency-injection)

#### Laravel project

[](#laravel-project)

Create your own service provider when your working in a [Laravel](https://laravel.com) project to bind the Redis class to the EventStoreInterface:

```
namespace App\Providers;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\ServiceProvider;
use Predis\Client as PredisClient;
use TwanHaverkamp\EventSourcingWithPhp\Event\EventDescriber\KebabCase;
use TwanHaverkamp\EventSourcingWithPhp\Event\EventStore\EventStoreInterface;
use TwanHaverkamp\EventStorageInRedisWithPhp\Event\EventStore\Redis;

class EventStoreServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->singleton(EventStoreInterface::class, function (Application $app) {
            return new Redis(
                new PredisClient([
                    'scheme' => 'tcp',
                    'host'   => config('redis.host'),
                    'port'   => config('redis.port'),
                ]),
                new KebabCase(),
            );
        });
    }
}
```

#### Symfony project

[](#symfony-project)

If you're working in a [Symfony](https://symfony.com/) project, you can leverage it's built-in "autowire" mechanism by registering the Event Store as a service in the `services.yaml`:

```
services:
  _defaults:
    bind:
      Predis\ClientInterface: '@redis.client'
      TwanHaverkamp\EventSourcingWithPhp\Event\EventDescriber\EventDescriberInterface: '@event.describer'
      TwanHaverkamp\EventSourcingWithPhp\Event\EventStore\EventStoreInterface: '@event_store.redis'

  # ...

  event.describer:
    class: TwanHaverkamp\EventSourcingWithPhp\Event\EventDescriber\KebabCase

  event_store.redis:
    class: TwanHaverkamp\EventStorageInRedisWithPhp\Event\EventStore\Redis

  redis.client:
    class: Predis\Client
    arguments:
      - { scheme: 'tcp', host: '%env(string:REDIS_HOST)%', port: '%env(int:REDIS_PORT)%' }

  # ...
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance76

Regular maintenance activity

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~160 days

Total

3

Last Release

132d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef80a2db2114f61389f75e7729ccae77d666fdbb0754d09f3604662f9e01f519?d=identicon)[TwanHaverkamp](/maintainers/TwanHaverkamp)

---

Top Contributors

[![twanhaverkamp](https://avatars.githubusercontent.com/u/38506134?v=4)](https://github.com/twanhaverkamp "twanhaverkamp (2 commits)")

---

Tags

event-sourcingphp-libraryphp8redis

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/twanhaverkamp-event-storage-in-redis-with-php/health.svg)

```
[![Health](https://phpackages.com/badges/twanhaverkamp-event-storage-in-redis-with-php/health.svg)](https://phpackages.com/packages/twanhaverkamp-event-storage-in-redis-with-php)
```

###  Alternatives

[rhubarbgroup/redis-cache

A persistent object cache backend for WordPress powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI.

51795.3k1](/packages/rhubarbgroup-redis-cache)[monospice/laravel-redis-sentinel-drivers

Redis Sentinel integration for Laravel and Lumen.

103830.5k](/packages/monospice-laravel-redis-sentinel-drivers)[jamescauwelier/psredis

Sentinel client for the popular php redis client

77392.9k5](/packages/jamescauwelier-psredis)[cache/predis-adapter

A PSR-6 cache implementation using Redis (Predis). This implementation supports tags

272.6M13](/packages/cache-predis-adapter)[symfony-bundles/redis-bundle

Symfony Redis Bundle

271.1M5](/packages/symfony-bundles-redis-bundle)[pdffiller/qless-php

PHP Bindings for qless

29113.2k1](/packages/pdffiller-qless-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
