AsyncZCached

Attributes
Methods
class zcached.AsyncZCached(host, port, pool_size=1, connection_attempts=3, reconnect=True, timeout_limit=10, buffer_size=2048, loop=None, protocol_type=None, **kwargs)[source]

Bases: object

Asynchronous ZCached 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 tasks, then you do not need more connections than 1.

  • connection_attempts (int) – The maximum number of attempts to establish a connection with the server.

  • reconnect (bool) – Flag indicating whether automatic reconnection attempt should be made in case of a broken connection (default is True).

  • 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.

  • loop (AbstractEventLoop | None) – The event loop to be used.

  • protocol_type (Optional[Type[StreamReaderProtocol]]) – The protocol type which is used to building protocol for managing the connection.

  • kwargs (AsyncConnectionPool)

connection_pool

The connection pool used by the client to manage connections to the server.

loop

The event loop used by the client for asynchronous operations.

async dbsize()[source]

Sends a db size command to the database server.

Return type:

Result[int]

async delete(key)[source]

Coroutine to delete a database record by key.

Parameters:

key (str) – Key of the record being deleted.

Return type:

Result[str]

async exists(key)[source]

Checks if the specified key exists in the database.

Parameters:

key (str) – The key to check for existence in the database.

Return type:

bool

Notes

Using this method directly may be unsafe as it does not verify the connections 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.

async flush()[source]

Sends a flush command to the database server.

Return type:

Result[str]

classmethod from_connection_pool(connection_pool)[source]

Creates a client instance from an existing connection pool.

Parameters:

connection_pool (AsyncConnectionPool) – The connection pool to be used by the client.

Return type:

Self

async get(key)[source]

Sends a get command to the database server.

Parameters:

key (str) – The key to retrieve the value from the database.

Return type:

Result

get_connection()[source]

Retrieves the least loaded connection from the connection pool. None if there is no any running connections.

Return type:

AsyncConnection | None

async is_alive()[source]

Checks if there is any active connection with the database server.

Return type:

bool

async keys()[source]

Sends a key command to the database server.

Return type:

Result[List[str]]

async lastsave()[source]

Sends a last save command to the database server.

Return type:

Result[int]

async mget(*keys)[source]

Coroutine 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.

Parameters:

keys (str) – Keys to retrieve values from the database.

Return type:

Result[dict[str, Any]]

async mset(**params)[source]

Coroutine to set multiple database records simultaneously. Example usage: client.mset(key1="value1", key2=False, key3=5)

Parameters:

params (Union[str, int, float, bool, list, tuple, dict, set, None]) – Keyword arguments representing key-value pairs to be set in the database.

Return type:

Result[str]

async ping()[source]

Sends a ping command to the database server.

Return type:

Result[str]

async run()[source]

Establishes connections with the database server using connection pool.

Return type:

None

async save()[source]

Sends a save command to the database server.

Return type:

Result[str]

async send(data)[source]

Method to send data to the server.

Return type:

Result

Parameters:

data (bytes)

async set(key, value)[source]

Coroutine to create a new database record.

Parameters:
Return type:

Result[str]