Connection¶
- defclose
- defconnect
- defis_connected
- defis_locked
- defreceive
- defsend
- deftry_reconnect
- defwait_for_response
- class zcached.Connection(host, port, connection_attempts=3, reconnect=True, timeout_limit=15, buffer_size=2048)[source]¶
Bases:
objectAn object to establish and manage a connection with the database server.
- Parameters:
host (
str) – The host address of the server to connect to.port (
int) – The port number of the server to connect to.buffer_size (
int) – The size of the buffer for receiving data from the server, in bytes. Larger values for buff_size may allow for more data to be received in a single operation, while smaller values can be more memory-efficient but slower.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.
- socket¶
The socket object for communicating with the server.
- buffer_size¶
The size of the buffer for receiving data from the server.
- 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.
- is_connected()[source]¶
A boolean indicating whether the connect method was successfully invoked. :rtype:
boolNote
This does not mean that the socket has a connection to the server. The socket connection may be broken, and we do not update it constantly.
- Return type:
- receive()[source]¶
Method to receive the response from the server. None if there is no data in the socket yet.
- try_reconnect()[source]¶
A method to attempt to reconnect to the server if the connection is broken. :rtype:
Result[bytes]Note
If the connection is successfully reestablished, the method return a Result object with a failure status and an informational message indicating that the connection was terminated but managed to reestablish it.