PHPackages                             petkakahin/eloquent-redis-mirror - 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. [Database &amp; ORM](/categories/database)
4. /
5. petkakahin/eloquent-redis-mirror

ActiveLibrary[Database &amp; ORM](/categories/database)

petkakahin/eloquent-redis-mirror
================================

Mirror Laravel Eloquent models to Redis for fast read access with automatic write-through synchronization

v1.0.0(today)015↑1700%MITPHPPHP ^8.2

Since Mar 19Pushed todayCompare

[ Source](https://github.com/PetkaKahin/eloquent-redis-mirror)[ Packagist](https://packagist.org/packages/petkakahin/eloquent-redis-mirror)[ Docs](https://github.com/PetkaKahin/eloquent-redis-mirror)[ RSS](/packages/petkakahin-eloquent-redis-mirror/feed)WikiDiscussions master Synced today

READMEChangelog (8)Dependencies (14)Versions (22)Used By (0)

Eloquent Redis Mirror
=====================

[](#eloquent-redis-mirror)

 Zero-config Redis caching layer for Laravel Eloquent.
 One trait. Same API. Reads from Redis.

 [![Latest Version](https://camo.githubusercontent.com/5440b562e1351a8967510de7428df8313cef564dc780b27faec35956cca4e618/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7065746b616b6168696e2f656c6f7175656e742d72656469732d6d6972726f722e737667)](https://packagist.org/packages/petkakahin/eloquent-redis-mirror) [![PHP Version](https://camo.githubusercontent.com/d50d1b2129dbfff1d98d152347ad9c25b11c6c36794bcbf5efa4eef0f70d3f34/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7065746b616b6168696e2f656c6f7175656e742d72656469732d6d6972726f722e737667)](https://packagist.org/packages/petkakahin/eloquent-redis-mirror) [![License](https://camo.githubusercontent.com/79be45ee39156af9126751c1f13dc934cc74828ee5a7c8d2406532b659b9a44b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7065746b616b6168696e2f656c6f7175656e742d72656469732d6d6972726f722e737667)](LICENSE)

 **Русская версия:** [README (RU)](docs/language/ru/README.md)

---

```
class Project extends Model
{
    use HasRedisCache;

    protected array $redisRelations = ['categories', 'tags'];
}

// Same Eloquent API — reads served from Redis:
Project::find(7);                                        // Redis GET
Project::with('categories.tasks')->find(7);              // ZRANGE + pipeline GET
$project->categories()->paginate(15);                    // ZCARD + ZRANGE
$project->categories()->exists();                        // ZCARD
$project->tags()->attach([5, 8]);                        // DB + auto-sync Redis
```

Add one trait to your models. Every `find()`, `with()`, `first()`, `paginate()`, `exists()` is served from Redis. Writes go to the database first, then automatically sync to Redis via model events. Cold start is handled transparently — first miss hits DB, warms Redis, subsequent reads are instant.

Features
--------

[](#features)

- **Transparent caching** — `find`, `findMany`, `with`, `first`, `paginate`, `exists` from Redis
- **Auto-sync on write** — create/update/delete/restore trigger Redis sync via events
- **Relations** — HasMany, HasOne, BelongsToMany, BelongsTo with Sorted Set indices
- **Pivot data** — BelongsToMany pivot attributes cached as separate keys
- **Custom relations** — third-party packages (`belongsToSortedMany`, etc.) via `$redisCustomRelations`
- **Cold start** — automatic DB fallback + warm-up with 24h TTL warmed flags
- **Fault-tolerant** — Redis down = transparent fallback to DB, no errors
- **Atomic writes** — `MULTI/EXEC` transactions, no partial state

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

[](#requirements)

- PHP 8.2+
- Laravel 11+ / 12+
- Redis (phpredis or predis)

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

[](#installation)

```
composer require petkakahin/eloquent-redis-mirror
```

ServiceProvider auto-discovered. No config files needed.

Quick Start
-----------

[](#quick-start)

```
use PetkaKahin\EloquentRedisMirror\Traits\HasRedisCache;

class Project extends Model
{
    use HasRedisCache;

    protected array $redisRelations = ['categories', 'tags'];

    public function categories(): HasMany { return $this->hasMany(Category::class); }
    public function tags(): BelongsToMany { return $this->belongsToMany(Tag::class); }
}

class Category extends Model
{
    use HasRedisCache;

    protected array $redisRelations = ['tasks'];
}

class Task extends Model
{
    use HasRedisCache;

    protected array $redisRelations = []; // leaf model
}
```

That's it. Every model in the eager-load chain needs the trait. Eloquent API stays the same.

Documentation
-------------

[](#documentation)

**English**[Documentation](docs/language/en/documentation.md)**Русский**[Документация](docs/language/ru/documentation.md)Testing
-------

[](#testing)

```
make tests   # 324 tests (Docker + Pest)
make stan    # PHPStan level 6
```

License
-------

[](#license)

MIT

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance100

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

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 ~0 days

Total

15

Last Release

0d ago

Major Versions

v0.2.7 → v1.0.02026-03-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/886430cbadee39820814de8c23e82dd5670bd4d7e17a034f3bfd2ccb820ecf39?d=identicon)[PetkaKahin](/maintainers/PetkaKahin)

---

Top Contributors

[![PetkaKahin](https://avatars.githubusercontent.com/u/76158669?v=4)](https://github.com/PetkaKahin "PetkaKahin (56 commits)")

---

Tags

laravelperformanceeloquentrediscachemirror

###  Code Quality

TestsPest

Static AnalysisPHPStan

### Embed Badge

![Health badge](/badges/petkakahin-eloquent-redis-mirror/health.svg)

```
[![Health](https://phpackages.com/badges/petkakahin-eloquent-redis-mirror/health.svg)](https://phpackages.com/packages/petkakahin-eloquent-redis-mirror)
```

###  Alternatives

[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

590440.9k2](/packages/spiritix-lada-cache)[ymigval/laravel-model-cache

Laravel package for caching Eloquent model queries

7636.6k2](/packages/ymigval-laravel-model-cache)[kirkbushell/eloquence

A set of extensions adding additional functionality and consistency to Laravel's awesome Eloquent library.

573942.3k1](/packages/kirkbushell-eloquence)[authentik/eloquent-cache

Easily cache your Laravel's Eloquent models

573.9k](/packages/authentik-eloquent-cache)[morilog/infinity-cache

Infinity cache for Laravel Eloquent models and queries

3115.8k](/packages/morilog-infinity-cache)[korridor/laravel-computed-attributes

Laravel package that adds computed attributes to eloquent models. A computed attribute is an accessor were the computed value is saved in the database.

1234.4k](/packages/korridor-laravel-computed-attributes)

PHPackages © 2026

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