PHPackages                             hesam1996/laravel-redis-entity - 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. hesam1996/laravel-redis-entity

ActiveLibrary

hesam1996/laravel-redis-entity
==============================

Generate clean Redis-backed entity service classes with full CRUD support for Laravel.

v0.1.2(1mo ago)311MITPHPPHP ^8.1

Since Jul 11Pushed 1mo agoCompare

[ Source](https://github.com/hesam1996/laravel-redis-entity)[ Packagist](https://packagist.org/packages/hesam1996/laravel-redis-entity)[ RSS](/packages/hesam1996-laravel-redis-entity/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (5)Versions (6)Used By (0)

Laravel Redis Entity
====================

[](#laravel-redis-entity)

A lightweight Laravel package for managing Redis-backed entities with automatic Read-Through caching and Cache Stampede protection.

It stores each entity as a **Redis Hash** and can transparently fall back to an Eloquent model when the cache is cold — no manual cache handling needed.

---

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

[](#installation)

```
composer require hesam1996/laravel-redis-entity

php artisan vendor:publish --tag=redis-entity-config
```

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

[](#quick-start)

Generate a pure Redis entity:

```
php artisan redis-entity:make sessions
```

Generate an entity backed by an Eloquent model (Read-Through Cache):

```
php artisan redis-entity:make products --model=Product
```

Usage:

```
$productEntity = new ProductRedisEntity();

$products = $productEntity->getAll();      // first call → DB, next calls → Redis
$product = $productEntity->get(42);       // single record

$productEntity->set('42', [...]);
$productEntity->forget('42');
$productEntity->clear();       // invalidate cache, next read re-warms from DB
```

How it works
------------

[](#how-it-works)

1️⃣ You call `getAll()` or `get($id)` on an entity

2️⃣ `warmIfCold()` checks if the Redis Hash exists

3️⃣ If cache is cold and a model is defined:

- a distributed lock is acquired (`Cache::store('redis')->lock()`)
- only **one** process fetches records from the database
- records are stored in Redis via `hydrateKey()` / `hydrateValue()`

4️⃣ Concurrent requests wait for the lock instead of hitting the database

5️⃣ All next reads are served directly from Redis — O(1) via Hash fields

---

Customization
-------------

[](#customization)

Each generated entity can override:

- `query()` → custom scopes, eager loading, column selection
- `hydrateKey()` → which field becomes the Hash key (default: primary key)
- `hydrateValue()` → what gets stored per record (default: `toArray()`)

---

Design Patterns Used
--------------------

[](#design-patterns-used)

### Template Method

[](#template-method)

- `Support/BaseRedisEntity.php` holds the shared algorithm
- Generated entities only define `$entity` and optionally `$model`

### Read-Through Cache

[](#read-through-cache)

- Cache miss → fetch from DB → populate Redis → return data

### Contract-Driven Design

[](#contract-driven-design)

- `Contracts/RedisEntityInterface.php` defines the public API

🟡 Entities never talk to the database directly — the base class decides when to warm the cache.

🟡 The lock always runs on the Redis store, independent of your app's default cache driver.

---

Why Redis Hashes?
-----------------

[](#why-redis-hashes)

- `HGETALL` for bulk reads — no `KEYS` / `SCAN`
- `HGET` for O(1) single-record access
- One `DEL` invalidates the whole entity

---

Implemented by Hesam Kazembeygi

📌 [My Website](https://kazembeygi.com)

📌 [My LinkedIn](https://www.linkedin.com/in/hessam-kazembeygi)

---

License
-------

[](#license)

Laravel Redis Entity is open-sourced software licensed under the [MIT license](https://opensource.org/license/MIT).

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance90

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

5

Last Release

50d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7229ea898dc519d97beea7713122b933a2fa2ec62a3754b6eb6183c2bcfa98eb?d=identicon)[hesam1996](/maintainers/hesam1996)

---

Top Contributors

[![hesam1996](https://avatars.githubusercontent.com/u/132776700?v=4)](https://github.com/hesam1996 "hesam1996 (5 commits)")

---

Tags

laravel-redislaravel redis crud generatorredis entityredis crudredis crud generator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hesam1996-laravel-redis-entity/health.svg)

```
[![Health](https://phpackages.com/badges/hesam1996-laravel-redis-entity/health.svg)](https://phpackages.com/packages/hesam1996-laravel-redis-entity)
```

###  Alternatives

[laravel/sail

Docker files for running a basic Laravel application.

1.9k220.0M1.5k](/packages/laravel-sail)[laravel/ai

The official AI SDK for Laravel.

1.1k6.4M360](/packages/laravel-ai)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k17.6M165](/packages/laravel-pulse)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

80732.6M270](/packages/laravel-mcp)[illuminate/queue

The Illuminate Queue package.

20433.5M1.9k](/packages/illuminate-queue)[propaganistas/laravel-disposable-email

Disposable email validator

6093.4M9](/packages/propaganistas-laravel-disposable-email)

PHPackages © 2026

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