Redis

    1. return [
    2. 'default' => [
    3. 'host' => env('REDIS_HOST', 'localhost'),
    4. 'auth' => env('REDIS_AUTH', ''),
    5. 'port' => (int) env('REDIS_PORT', 6379),
    6. 'db' => (int) env('REDIS_DB', 0),
    7. 'pool' => [
    8. 'min_connections' => 1,
    9. 'max_connections' => 10,
    10. 'connect_timeout' => 10.0,
    11. 'wait_timeout' => 3.0,
    12. 'heartbeat' => -1,
    13. 'max_idle_time' => (float) env('REDIS_MAX_IDLE_TIME', 60),
    14. ],
    15. ];
    1. <?php
    2. return [
    3. 'default' => [
    4. 'host' => env('REDIS_HOST', 'localhost'),
    5. 'auth' => env('REDIS_AUTH', ''),
    6. 'port' => (int) env('REDIS_PORT', 6379),
    7. 'db' => (int) env('REDIS_DB', 0),
    8. 'pool' => [
    9. 'min_connections' => 1,
    10. 'max_connections' => 10,
    11. 'connect_timeout' => 10.0,
    12. 'wait_timeout' => 3.0,
    13. 'heartbeat' => -1,
    14. 'max_idle_time' => (float) env('REDIS_MAX_IDLE_TIME', 60),
    15. ],
    16. ],
    17. // 增加一个名为 foo 的 Redis 连接池
    18. 'foo' => [
    19. 'auth' => env('REDIS_AUTH', ''),
    20. 'port' => (int) env('REDIS_PORT', 6379),
    21. 'db' => 1,
    22. 'pool' => [
    23. 'max_connections' => 10,
    24. 'connect_timeout' => 10.0,
    25. 'wait_timeout' => 3.0,
    26. 'heartbeat' => -1,
    27. 'max_idle_time' => (float) env('REDIS_MAX_IDLE_TIME', 60),
    28. ],
    29. ],
    30. ];

    使用工厂类

    1. <?php
    2. use Hyperf\Redis\RedisFactory;
    3. // 通过 DI 容器获取或直接注入 RedisFactory 类
    4. $redis = $this->container->get(RedisFactory::class)->get('foo');
    5. $result = $redis->keys('*');