AsyncConnectionPool¶
- defcleanup_broken_connections
- asyncclose
- asyncextend_pool_by_connections
- asyncextend_pool_by_size
- defget_least_loaded_connection
- defis_empty
- defis_full
- defis_working
- asyncreconnect
- defreduce_pool_connections
- asyncsetup
- class zcached.AsyncConnectionPool(pool_size, connection_factory)[source]¶
Bases:
objectA pool of asynchronous connections.
- Parameters:
pool_size (
int) – The maximum size of the connection pool.connection_factory (
Callable[[],AsyncConnection]) – A callable that returns a new instance of AsyncConnection.
- property broken_connections: List[AsyncConnection]¶
List of all broken (not connected) connections in the pool.
- cleanup_broken_connections()[source]¶
Closes broken connections and removes them from the list of connections.
- Return type:
- property connected_connections: List[AsyncConnection]¶
List of all connected connections in the pool.
- property connection_factory: Callable[[], AsyncConnection]¶
The factory function to create a new connection.
- property connections: List[AsyncConnection]¶
List of all connections in the pool.
- async extend_pool_by_connections(connections)[source]¶
Extends the pool with existing connections. The pool size will be increased if necessary.
- Parameters:
connections (
Iterable[AsyncConnection]) – An iterable of existing connections to add to the pool.- Return type:
- async extend_pool_by_size(size)[source]¶
Extends the pool by a specified number of connections. The pool size will be increased if necessary.
- get_least_loaded_connection()[source]¶
Get the least loaded connection from the pool. Only working connections are considered.
- Raises:
IndexError – If the pool is empty.
- Return type:
- async reconnect(only_broken_connections=True)[source]¶
Attempts to reconnect connections in the pool. Returns the number of connected connections after reconnection.
- reduce_pool_connections(amount, delete_pending_connections=False)[source]¶
Reduces the size of the connection pool by a specified amount. By default, the method first removes non-working connections, when this is not enough it takes connections that have 0 pending requests and removes them too. If a connection has any pending requests, it doesn’t delete it, well, unless the delete_pending_connections parameter is on True.