承接 bilaliqbalr/laravel-redis 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

bilaliqbalr/laravel-redis

Composer 安装命令:

composer require bilaliqbalr/laravel-redis

包简介

This package will provide redis based laravel auth driver

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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:

  1. No need to create migration files, just provide required columns in $fillable and this package will take care of the rest
  2. Perform CRUD operations just like doing them in Laravel
  3. Search model functionality
  4. Managing relations
  5. 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 bilaliqbalr/laravel-redis 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-09-23