link1st / laravel-redis by link1st

laravel-redis
43
0
2
Package Data
Maintainer Username: link1st
Maintainer Contact: link12stl@gmail.com (link1st)
Package Create Date: 2017-07-15
Package Last Update: 2017-08-26
Language: PHP
License: MIT
Last Refreshed: 2024-04-24 03:04:10
Package Statistics
Total Downloads: 43
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

laravel-redis

laravel-redis,本laravel包使用的是PHPRedis 需要开启Redis扩展才能使用,非~~predis~~

能提升代码执行效率,对应常见的string类型的get和set方法支持数组

配置laravel-ide-helper一起使用有代码提示

支持redis集群

安装

加载包

"link1st/laravel-redis": "dev-master"

composer require link1st/laravel-redis

在配置文件中添加 config/app.php

    'providers' => [
        /**
         * 添加供应商
         */
        link1st\RedisCache\RedisCacheServiceProvider::class,
    ],
    'aliases' => [
         /**
          * 添加别名
          */
        'RedisCache' => link1st\RedisCache\Facades\RedisCache::class,
    ],

生成配置文件

php artisan vendor:publish

设置参数 config/redis_cache.php

使用

  • 默认reids连接
// set 第二个参数可以为数组 第三个参数为ttl时间,默认不设置过期时间
\RedisCache::set('name',['name'=>'xiaoming']);

// get 返回一个数组
\RedisCache::get('name');

  • 切换redis连接
// - 需要提前在 redis_cache.php 配置redis连接
\RedisCache::openRedis('redis_config1')->get('name'));


$redis = \RedisCache::openRedis('redis_config1');
$redis->get('name');