PHPackages                             sm-me/laravel-redis-model-cache - 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. sm-me/laravel-redis-model-cache

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

sm-me/laravel-redis-model-cache
===============================

Optimized Redis model and hash-set caching service for Laravel Eloquent.

v1.0.0(today)01↑2900%MITPHPPHP ^8.2

Since Jul 1Pushed todayCompare

[ Source](https://github.com/sm-me-dev/laravel-redis-model-cache)[ Packagist](https://packagist.org/packages/sm-me/laravel-redis-model-cache)[ RSS](/packages/sm-me-laravel-redis-model-cache/feed)WikiDiscussions main Synced today

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

Laravel Redis Model Cache
=========================

[](#laravel-redis-model-cache)

Optimized, high-performance Redis model and hash-set caching service for Laravel Eloquent.

---

🌟 Overview
----------

[](#-overview)

The **Laravel Redis Model Cache** package seamlessly integrates a Redis caching layer natively tailored for your Laravel 12 application. This is not your typical `Cache::remember()` wrapper. Instead, it provides a highly optimized, index-aware caching structure for Eloquent models built on top of Redis Hash Sets and Sorted Sets, resulting in lightning-fast lookups without hitting the database for relational operations.

### Key Features:

[](#key-features)

- 🚀 **High Performance:** Uses Redis pipelining and native hashes (`HSET`, `HGETALL`) for bulk serialization and deserialization.
- 🔍 **Advanced Indexing:** Build and query dynamic custom indices, regular indices (`SADD`), and sorted score sets (`ZADD`).
- 🛠️ **Seamless Integration:** Zero-configuration dependency injection via `RedisConnectionResolver`.
- 🌐 **Pluggable Match Strategy:** Flexible string matching interface. Customize text normalizations natively (e.g. Arabic/Farsi translations).
- 🧑‍💻 **Dev-Friendly Console:** Built-in Artisan commands to monitor cache memory, keys, and TTL thresholds.

---

📦 Installation
--------------

[](#-installation)

This package is a standalone Packagist-ready module. Install it into your Laravel application using Composer:

```
composer require sm-me/laravel-redis-model-cache
```

The package supports **Laravel Auto-Discovery**, so the `RedisModelCacheServiceProvider` will be registered automatically.

⚙️ Configuration
----------------

[](#️-configuration)

Publish the configuration file using Artisan:

```
php artisan vendor:publish --tag=redis-model-cache-config
```

This will create a `config/redis-model-cache.php` file where you can define:

- Your target Redis connection (defined in `config/database.php`).
- Global Time-to-Live (TTL) behaviors.
- Deletion scan strategies (`keys` vs `scan`).

---

🛠️ Usage
--------

[](#️-usage)

### Basic Dependency Injection

[](#basic-dependency-injection)

You can inject the core `RedisModelService` directly or construct it on the fly:

```
use Sm_mE\RedisModelCache\RedisModelService;
use App\Models\User;

$cacheService = app(RedisModelService::class, [
    'model_class' => User::class,
    'indexes' => ['role_id'],
    'sorted' => ['created_at'],
    'ttl' => 3600 // 1 hour TTL
]);

// Fetch and Cache your query
$users = $cacheService->rememberAll(function () {
    return User::where('active', true)->get();
});
```

### Advanced Querying (Where)

[](#advanced-querying-where)

When data exists in the hash set, the package simulates Eloquent filtering entirely within Redis memory:

```
// Queries Redis memory directly if cache is warm
$activeAdmins = $cacheService->where(['role_id' => 1, 'active' => true]);
```

### Sorted Sets Pagination

[](#sorted-sets-pagination)

Need to paginate cached data natively via Redis ZSets? Easy:

```
// Retrieve page 1 (first 10 records) sorted by 'created_at' index.
$latestUsers = $cacheService->paginateSorted('created_at', page: 1, perPage: 10);
```

### Global Helper Functions

[](#global-helper-functions)

For quick operations anywhere in your app, use the built-in global helper methods:

```
// Resolves RedisHelperService for generic hash sets
$data = redisHelper(ttl: 300)->rememberSet('app:settings', 'theme', fn () => 'dark');

// Resolves RedisModelService for Eloquent operations
$service = redisModelHelper(User::class, indexes: ['department_id']);
```

---

🏗 Pluggable String Matching (ModelMatchStrategy)
------------------------------------------------

[](#-pluggable-string-matching-modelmatchstrategy)

By default, the package relies on `DefaultModelMatchStrategy` which uses simple `strtolower()` logic for finding records within memory (`remember()`).

You can define and bind your own complex normalization rules in your app's `AppServiceProvider`:

```
namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Sm_mE\RedisModelCache\Contracts\ModelMatchStrategy;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->bind(ModelMatchStrategy::class, FarsiModelMatchStrategy::class);
    }
}
```

---

📊 Artisan Cache Monitor
-----------------------

[](#-artisan-cache-monitor)

Manage and monitor your application's Redis footprint directly from the CLI:

```
# View cache usage statistics and memory layout
php artisan redis:monitor-cache info

# Scan specific keys by pattern (supports --detailed)
php artisan redis:monitor-cache keys --pattern="users:hash:*"

# Detect orphaned keys missing TTL
php artisan redis:monitor-cache ttl

# Safely flush specific cache buckets
php artisan redis:monitor-cache clear --pattern="users:*"
```

---

📜 License
---------

[](#-license)

The **Laravel Redis Model Cache** is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/45b482b959a84a565d6c5f9f95b22ad9c5441002c4a4334d04e5521e7e00783b?d=identicon)[sm-me](/maintainers/sm-me)

---

Top Contributors

[![sm-me-dev](https://avatars.githubusercontent.com/u/52349309?v=4)](https://github.com/sm-me-dev "sm-me-dev (3 commits)")

---

Tags

laravelmodeleloquentrediscachepackagist

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/sm-me-laravel-redis-model-cache/health.svg)

```
[![Health](https://phpackages.com/badges/sm-me-laravel-redis-model-cache/health.svg)](https://phpackages.com/packages/sm-me-laravel-redis-model-cache)
```

###  Alternatives

[spiritix/lada-cache

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

592456.3k2](/packages/spiritix-lada-cache)[spatie/laravel-medialibrary

Associate files with Eloquent models

6.1k43.2M623](/packages/spatie-laravel-medialibrary)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M93](/packages/mongodb-laravel-mongodb)[laravel/pulse

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

1.7k15.1M129](/packages/laravel-pulse)[prettus/l5-repository

Laravel 8|9|10|11|12|13 - Repositories to the database layer

4.3k11.3M157](/packages/prettus-l5-repository)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M184](/packages/laravel-ai)

PHPackages © 2026

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