redtrio.lowlevel.connections

The connections module handles connecting to the server.

Classes:

ConnectionPool

Module Contents

Classes

ConnectionPool

This class implements a default connection pool.

class redtrio.lowlevel.connections.ConnectionPool(host: str, port: int, max_connections: int = 50, spawn_connection: t.Callable = trio.open_tcp_stream)

This class implements a default connection pool.

host

The address to connect to.

Type

str

port

The port to connect to.

Type

int

max_connections

The maximum number of connections to keep.

Type

int

spawn_connection

The function used to spawn a new connection.

used_connections

A set containing connections currently in use.

Type

set

pool

The pool of unused connections.

async wait_for_connection(self)

Wait for a connection to become available.

Returns immediately if pool has a connection available. Otherwise, if max_connections has not been reached, spawns a new connection. If max_connections has been reached, wait for one to become available.

Returns

A connection to the Redis server.

put_connection(self, connection: trio.abc.Stream)

Put a connection back in the pool, removing it from used_connections.

Parameters

connection – The connection to put back.

remove_connection(self, connection: trio.abc.Stream)

Remove a connection entirely, whether it is in used_connections or the pool.

Parameters

connection – The connection to remove.