AsyncConnection¶
- asyncclose
- asyncconnect
- asyncopen_connection
- asyncreceive
- asyncsend
- asynctry_reconnect
- asyncwait_for_response
- class zcached.AsyncConnection(host, port, connection_attempts=3, reconnect=True, timeout_limit=15, buffer_size=2048, loop=None, protocol_type=None)[source]¶
Bases:
Connection,Generic[ProtocolT]An asynchronous connection object to manage communication with the server.
- Parameters:
host (
str) – The host address of the server to connect to.port (
int) – The port number of the server to connect to.connection_attempts (
int) – The maximum number of attempts to establish a connection with the server. If the maximum number of attempts is exceeded, an error will be raised.reconnect (
bool) – Flag indicating whether automatic reconnection attempt should be made in case of a broken connection.timeout_limit (
int) – The maximum time in seconds to wait for a response from the server.buffer_size (
int) – The size of the buffer for receiving data from the server, in bytes. Larger values for buffer_size may allow for more data to be received in a single operation, while smaller values can be more memory-efficient but slower.loop (
AbstractEventLoop|None) – The event loop to run asynchronous tasks. If None, the default event loop will be used.protocol_type (
Optional[Type[TypeVar(ProtocolT, bound=StreamReaderProtocol)]]) – The protocol type which is used to building protocol for managing the connection.
- connection_attempts¶
The maximum number of attempts to establish a connection with the server.
- reconnect¶
Flag indicating whether automatic reconnection attempt should be made in case of a broken connection.
- timeout_limit¶
The maximum time in seconds to wait for a response from the server.
- buffer_size¶
The size of the buffer for receiving data from the server, in bytes.
- loop¶
The event loop to run asynchronous tasks.
- async close()[source]¶
Closes the connection by closing the writer, and waiting until the writer is fully closed.
- Return type:
- async connect()[source]¶
Coroutine to establish a connection with the server asynchronously.
- Return type:
- property reader: StreamReader | None¶
The asyncio.StreamReader object for reading data from the server. If available.
- async receive(timeout_limit=None)[source]¶
Coroutine to receive data from the reader.
NOT TASK SAFE.
- Parameters:
timeout_limit (
float|None) – The maximum time in seconds to wait for a response from the server.- Raises:
asyncio.TimeoutError – If the timeout limit has been exceeded.
- Return type:
- property transport: None | WriteTransport¶
The transport object for the connection, if StreamWriter is available.
- async try_reconnect()[source]¶
A method to attempt to reconnect to the server if the connection is broken.