定制 petkakahin/eloquent-redis-mirror 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

petkakahin/eloquent-redis-mirror

最新稳定版本:v1.0.0

Composer 安装命令:

composer require petkakahin/eloquent-redis-mirror

包简介

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

README 文档

README

Eloquent Redis Mirror

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

Latest Version PHP Version License

Русская версия: README (RU)

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

  • Transparent cachingfind, 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 writesMULTI/EXEC transactions, no partial state

Requirements

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

Installation

composer require petkakahin/eloquent-redis-mirror

ServiceProvider auto-discovered. No config files needed.

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

English Documentation
Русский Документация

Testing

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

License

MIT

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固