ZCached¶
- class zcached.ZCached(host, port=7556, pool_size=1, buffer_size=2048, connection_attempts=3, reconnect=True, timeout_limit=10, **kwargs)[source]¶
Bases:
objectZCached client to connect to the server and send commands.
- Parameters:
host (
str) – Server host address.port (
int) – Server port number.pool_size (
int) – Number of connections to be created in the connection pool. If you do not send a large number of requests simultaneously in other threads, then you do not need more connections than 1.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. This value is also considered while reconnecting.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.kwargs (
ConnectionPool) – Optional keyword arguments.
- connection_pool¶
The connection pool used by the client to manage connections to the server.
- exists(key)[source]¶
Checks if the specified key exists in the database.
Notes
Using this method directly may be unsafe as it does not verify the connection status. When the key exists in the database, but the connection is broken, the value False will be returned. Because of this it’s recommended to use this method only when the connection to the server is guaranteed.
- classmethod from_connection_pool(connection_pool)[source]¶
Creates a client instance from an existing connection pool.
- Parameters:
connection_pool (
ConnectionPool) – The connection pool to be used by the client.- Return type:
Self
- get_connection()[source]¶
Retrieves the least loaded connection from the connection pool. None if there is no any running connections.
- Return type:
- is_alive()[source]¶
Checks if the client is currently connected to the server. :rtype:
boolNote
This method sends a ping command to the connected server.
- Return type:
- mget(*keys)[source]¶
Method to send a mget command to the database. This command allows you to retrieve multiple values simultaneously.
Example usage:
client.mget("key1", "key2", "key3")Note
For every key that does not hold a string value or does not exist, the special value None is returned. Because of this, the operation never fails.