Download the PHP package hesam1996/laravel-redis-entity without Composer
On this page you can find all versions of the php package hesam1996/laravel-redis-entity. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hesam1996/laravel-redis-entity
More information about hesam1996/laravel-redis-entity
Files in hesam1996/laravel-redis-entity
Package laravel-redis-entity
Short Description Generate clean Redis-backed entity service classes with full CRUD support for Laravel.
License MIT
Informations about the package 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
Quick Start
Generate a pure Redis entity:
Generate an entity backed by an Eloquent model (Read-Through Cache):
Usage:
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
Each generated entity can override:
query()→ custom scopes, eager loading, column selectionhydrateKey()→ which field becomes the Hash key (default: primary key)hydrateValue()→ what gets stored per record (default:toArray())
Design Patterns Used
Template Method
Support/BaseRedisEntity.phpholds the shared algorithm- Generated entities only define
$entityand optionally$model
Read-Through Cache
- Cache miss → fetch from DB → populate Redis → return data
Contract-Driven Design
Contracts/RedisEntityInterface.phpdefines 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?
HGETALLfor bulk reads — noKEYS/SCANHGETfor O(1) single-record access- One
DELinvalidates the whole entity
Implemented by Hesam Kazembeygi
License
Laravel Redis Entity is open-sourced software licensed under the MIT license.
All versions of laravel-redis-entity with dependencies
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/console Version ^10.0|^11.0|^12.0|^13.0
illuminate/redis Version ^10.0|^11.0|^12.0|^13.0