makise-co/redis-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

makise-co/redis-bundle

Composer 安装命令:

composer require makise-co/redis-bundle

包简介

Makise-Co Redis integration bundle

README 文档

README

Makise-Co Redis integration bundle

Usage

  • Add RedisServiceProvider to your app config
  • Create redis configuration file in config/redis.php:
    <?php
    
    declare(strict_types=1);
    
    use function MakiseCo\Env\env;
    
    return [
        'defaults' => [
            // a connection pool named as "example" will be used as default connection pool
            'connection' => 'example',
        ],
        'connections' => [
            // "example" is a pool name
            'example' => [
                'connection' => [
                    'host' => env('REDIS_HOST', '127.0.0.1'),
                    'port' => (int)env('REDIS_PORT', 6379),
                    'password' => env('REDIS_PASSWORD'),
                    'database' => (int)env('REDIS_DATABASE', 0),
    //                'timeout' => 10.0,
    //                'readTimeout' => 5.0,
    //                'retryInterval' => 5,
                ],
                'pool' => [
                    'minActive' => (int)env('REDIS_POOL_MIN_ACTIVE', 0),
                    'maxActive' => (int)env('REDIS_POOL_MAX_ACTIVE', 2),
                    'maxWaitTime' => (float)env('REDIS_POOL_MAX_WAIT_TIME', 5.0),
                    'maxIdleTime' => (int)env('REDIS_POOL_MAX_IDLE_TIME', 30),
                    'validationInterval' => (float)env('REDIS_POOL_VALIDATION_INTERVAL', 30.0),
                ],
            ],
        ],
    ];
  • Initialize redis connection pools:
    /** @var \Psr\Container\ContainerInterface $container */
    // redis connection pools are automatically initialized for HTTP server
    $container->get(\MakiseCo\Redis\RedisManager::class)->initPools();
  • Take connection pool from RedisManager:
    /** @var \Psr\Container\ContainerInterface $container */
    $redisManager = $container->get(\MakiseCo\Redis\RedisManager::class);
    
    $pool = $redisManager->getPool('example');
    // or get default connection pool
    $pool = $redisManager->getPool();
    
    $redis = $pool->borrow();
    // do something with Redis connection
    try {
        $redis->set('test', '1');
    } finally {
        $pool->return($redis);
    }
    
    // or use LazyConnection as an abstraction over connection pool
    $lazyConnection = $redisManager->getLazyConnection('example');
    // or get lazy connection for default connection pool
    $lazyConnection = $redisManager->getLazyConnection();
    $lazyConnection->set('test', '1');

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固