bilaliqbalr/laravel-redis
Composer 安装命令:
composer require bilaliqbalr/laravel-redis
包简介
This package will provide redis based laravel auth driver
README 文档
README
As name suggested this package will let you use Redis as a database instead of using it just for caching purpose. It works almost the same way as using Laravel Eloquent but with some differences. With this package forget the pain of naming keys and managing them in Redis. Some of the core features are as follows:
- No need to create migration files, just provide required columns in
$fillableand this package will take care of the rest - Perform CRUD operations just like doing them in Laravel
- Search model functionality
- Managing relations
- Laravel auth backed by Redis
Installation
You can install the package via composer:
composer require bilaliqbalr/laravel-redis
You can publish the config file with:
php artisan vendor:publish --provider="Bilaliqbalr\LaravelRedis\LaravelRedisServiceProvider" --tag="laravel-redis-config"
Usage
To create new redis model run this command
php artisan redis:model Post
Prefixes
Prefixes are used to maintain the key structure for specific model, this package creates prefixes by default using Model name, and in case you want to change it you can do this as follow
public function prefix() : string { return 'post'; }
Change connection
You can change redis connection in model as well
protected $connection = "redis";
Searching model by specific column
In case you need to get model based on specific field, you can do this by using $searchBy
where you just need to specify column names in the list and this package will store a new key value pair
where key is {model}:column:%s (%s is the column value) where value will be the model id to fetch required model.
protected $searchBy = [ 'title', ];
To get model based on that title field, you can do this as follows
$post = Post::searchByTitle("iphone"); # This works the same way as we do while using eloquent # Post::where('title', 'iphone')->first();
Other operations like create, update and delete works same as in Laravel
# Creating new post $post = Post::create([ 'user_id' => 1, 'title' => 'iPhone 13 release', 'description' => 'Lorem ipsum dolor', ]); # Getting data is a bit different $post = Post::get(1); // 1 is the model id # Get post by title $post = Post::searchByTitle('iphone'); # Update post info $post->update([ 'description' => 'Lorem ipsum dolor sat amet' ]); # Delete post $post->delete(); // or Post::destroy(1);
Get all records keys
// return list of all records keys from redis $post->getAllKeys(); // Return list of all records ids $post->getAllKeys(true);
Add new searchBy fields
If you need to add new searchBy field after you have records in your redis database, then you need to run this command to make old records searchable with new column
php artisan refresh:search_by App\\Redis\\Post
Managing model relations
With this package you can even create relation between models but that is not like the one in Laravel, as redis is not a relational database.
# User.php # Adding post relation public function posts() { return $this->relation(new \App\Models\Redis\Post); }
# Creating post under user # Below will automatically add user_id field in the Post model. $post = $user->posts()->create([ 'title' => 'iPhone 13 pro', 'description' => 'Lorem ipsum dolor', ]); # Getting all user posts $posts = $user->post()->get(); $paginatedPosts = $user->post()->paginate();
Auth
# In config/auth.php 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'redis', // use provider name as in laravel-redis.php config file ], ],
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
bilaliqbalr/laravel-redis 适用场景与选型建议
bilaliqbalr/laravel-redis 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 158 次下载、GitHub Stars 达 13, 最近一次更新时间为 2021 年 09 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「laravel-redis」 「bilaliqbalr」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bilaliqbalr/laravel-redis 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bilaliqbalr/laravel-redis 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bilaliqbalr/laravel-redis 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
Boot a Laravel project on any machine with one command: app:serve installs missing tools (PHP, Node, Composer, Herd, Docker), creates .env, sets up the database, runs migrations, builds assets, starts a queue worker and serves via Herd, Sail or artisan serve; app:down cleanly stops everything it sta
Branded, diagnostic error pages (500, 403, 404, 419, 503) for Filament — native Filament UI, dark mode and translations out of the box.
Turn any PDF into a Pingen-ready A4 letter (generated address cover page + A4 normalisation + safe margins) and send it through the Pingen print & mail API. Laravel-first.
统计信息
- 总下载量: 158
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-09-23