VOOZH about

URL: https://deepwiki.com/hypervel/redis/6-connection-management

⇱ Connection Management | hypervel/redis | DeepWiki


Loading...
Menu

Connection Management

This document provides an overview of the connection management subsystem in the hypervel/redis package. The system organizes Redis connections through a three-tier architecture: RedisFactory manages named connection pools, RedisPool handles connection lifecycle and pooling, and RedisProxy provides pool-specific client instances.

The connection management subsystem enables applications to maintain separate Redis connections for different purposes (e.g., default, cache, session), with each pool having independent configuration and resource limits.

Primary Components:

  • RedisFactory - Creates and manages RedisProxy instances for named pools (see page 6.1)
  • RedisPool - Extends Hyperf's pool to create RedisConnection instances (see page 6.2)
  • RedisProxy - Pool-specific Redis client instances (see page 6.3)

System Architecture

The connection management subsystem separates concerns across three layers:

  1. Factory Layer - RedisFactory reads configuration from ConfigInterface and creates RedisProxy instances for each configured pool
  2. Proxy Layer - RedisProxy extends Redis class with pool-specific configuration via the poolName property
  3. Pool Layer - RedisPool extends HyperfRedisPool and overrides createConnection() to return RedisConnection instances

This architecture allows multiple named pools (e.g., default, cache, session) to coexist with independent connection limits and Redis server endpoints.

Component Relationships

Diagram: Connection Management Class Structure


Sources: src/RedisFactory.php1-37 src/RedisProxy.php1-17 src/RedisPool.php1-16

Multi-Pool Connection Flow

Diagram: Named Pool Connection Acquisition


Sources: src/RedisFactory.php19-26 src/RedisFactory.php28-36 src/RedisPool.php12-15

Component Overview

RedisFactory

Location: src/RedisFactory.php1-37

The RedisFactory class implements a service locator pattern for named Redis pools. It reads pool configuration from ConfigInterface during construction and creates corresponding RedisProxy instances using Hyperf's make() function.

Properties:

  • protected array $proxies - Associative array mapping pool names to RedisProxy instances

Methods:

  • __construct(ConfigInterface $config) - Reads redis config key, iterates pools, creates proxies
  • get(string $poolName): RedisProxy - Returns proxy by name or throws InvalidRedisProxyException

See: Page 6.1 for detailed documentation

Sources: src/RedisFactory.php14-36

RedisPool

Location: src/RedisPool.php1-16

The RedisPool class extends Hyperf\Redis\Pool\RedisPool and overrides the createConnection() method to instantiate RedisConnection instead of the default Hyperf connection class. This substitution enables Laravel-compatible transformation behavior.

Methods:

  • createConnection(): ConnectionInterface - Returns new RedisConnection($container, $this, $config)

See: Page 6.2 for detailed documentation

Sources: src/RedisPool.php12-15

RedisProxy

Location: src/RedisProxy.php1-17

The RedisProxy class extends the main Redis client and sets the poolName property to specify which connection pool to use. This allows the factory to return type-safe proxy instances bound to specific pools.

Constructor:

  • __construct(PoolFactory $factory, string $pool) - Calls parent constructor and sets $this->poolName = $pool

See: Page 6.3 for detailed documentation

Sources: src/RedisProxy.php9-16

Integration Points

The connection management system integrates with the broader hypervel/redis architecture through several key interfaces:

ComponentIntegration PointPurpose
RedisFactoryConfigInterfaceReads Redis pool configurations
RedisPoolHyperfRedisPoolExtends Hyperf's pooling capabilities
RedisProxyRedis classInherits main Redis client functionality

This architecture ensures that connection management remains transparent to application code while providing efficient resource utilization through connection pooling and proxy management.

Sources: src/RedisFactory.php7 src/RedisPool.php8 src/RedisProxy.php7