graph LR
Connection_Abstraction["Connection Abstraction"]
Connection_Pooling["Connection Pooling"]
Sentinel_Integration["Sentinel Integration"]
Cluster_Integration["Cluster Integration"]
Exception_Handling["Exception Handling"]
Connection_Abstraction -- "uses" --> Exception_Handling
Connection_Pooling -- "uses" --> Connection_Abstraction
Sentinel_Integration -- "relies on" --> Connection_Pooling
Sentinel_Integration -- "uses" --> Exception_Handling
Cluster_Integration -- "relies on" --> Connection_Pooling
Cluster_Integration -- "uses" --> Exception_Handling
The Connection Management subsystem in redis-py is crucial for establishing and maintaining connections to various Redis deployments. It abstracts the complexities of network communication, connection pooling, and handling different Redis topologies (standalone, Sentinel, Cluster).
This component provides the foundational classes for managing individual connections to a Redis server. It handles the low-level details of establishing TCP or Unix socket connections, sending commands, and receiving responses. It also includes support for SSL/TLS connections.
Related Classes/Methods:
redis.connection.Connection(729:800)redis.connection.SSLConnection(1017:1185)redis.connection.UnixDomainSocketConnection(1188:1220)redis.asyncio.connection.Connection(722:776)redis.asyncio.connection.SSLConnection(779:843)redis.asyncio.connection.UnixDomainSocketConnection(915:936)
This component manages a pool of connections to Redis, improving performance by reusing existing connections instead of establishing new ones for each operation. It handles connection lifecycle, including creation, release, and optional blocking behavior when the pool is exhausted.
Related Classes/Methods:
redis.connection.ConnectionPool(1308:1647)redis.connection.BlockingConnectionPool(1650:1817)redis.asyncio.connection.ConnectionPool(1030:1252)redis.asyncio.connection.BlockingConnectionPool(1255:1332)
This component provides support for connecting to and managing Redis Sentinel deployments. It enables the client to discover the current master and replica nodes, handle failovers, and automatically re-route commands to the correct master.
Related Classes/Methods:
redis.sentinel.Sentinel(197:420)redis.sentinel.SentinelConnectionPool(136:194)redis.sentinel.SentinelManagedConnection(19:81)redis.asyncio.sentinel.Sentinel(166:400)redis.asyncio.sentinel.SentinelConnectionPool(95:163)redis.asyncio.sentinel.SentinelManagedConnection(25:88)
This component handles connections and command routing within a Redis Cluster environment. It manages slot mapping, handles redirection errors (MOVED/ASK), and discovers cluster nodes, ensuring commands are sent to the appropriate shard.
Related Classes/Methods:
redis.cluster.RedisCluster(455:1358)redis.cluster.NodesManager(1441:1861)redis.asyncio.cluster.RedisCluster(98:988)redis.asyncio.cluster.NodesManager(1210:1517)
This component defines a hierarchy of custom exceptions specific to Redis operations and connection issues. It provides a structured way to handle errors such as connection failures, timeouts, authentication errors, and Redis-specific response errors.
Related Classes/Methods: