Sync Cluster

class aerospike_sdk.sync.cluster.Cluster[source]

Bases: object

Synchronous cluster handle from sync.cluster_definition.ClusterDefinition.connect.

Mirrors Cluster but uses SyncClient and SyncSession.

Example:

with ClusterDefinition("localhost", 3100).connect() as cluster:
    session = cluster.create_session(Behavior.DEFAULT)

See also

Cluster

__init__(sdk_client)[source]

Initialize a Cluster instance.

Parameters:

sdk_client (SyncClient) – The underlying SyncClient instance

Note

This should not be called directly. Use ClusterDefinition.connect() instead.

create_session(behavior=None)[source]

Return a SyncSession for this cluster.

A session represents a logical connection to the cluster with specific behavior settings that control how operations are performed (timeouts, retry policies, consistency levels, etc.). :type behavior: Optional[Behavior] :param behavior: Defaults to DEFAULT.

Return type:

SyncSession

Returns:

A new sync session bound to this cluster’s client.

See also

create_session()

create_transactional_session(behavior=None)[source]

Return a SyncTransactionalSession for a multi-record transaction.

Equivalent to create_session(behavior).begin_transaction() — the returned context manager allocates a fresh Txn on entry and commits/aborts on exit.

Multi-record transactions require an Aerospike server running in strong-consistency (SC) mode on the target namespace.

Parameters:

behavior (Optional[Behavior]) – Optional Behavior for operations inside the transaction. Defaults to Behavior.DEFAULT when omitted.

Return type:

SyncTransactionalSession

Returns:

A SyncTransactionalSession bound to this cluster’s client and behavior.

Example:

with cluster.create_transactional_session() as tx:
    tx.upsert(accounts.id("A")).bin("balance").set_to(100).execute()
    tx.upsert(accounts.id("B")).bin("balance").set_to(200).execute()

See also

create_session(): Non-transactional session. create_transactional_session(): Async equivalent.

is_connected()[source]

Checks if the cluster connection is currently active.

Return type:

bool

Returns:

True if the connection is active, False otherwise

close()[source]

Closes the cluster connection and releases all associated resources.

This method closes the underlying client connection. It should be called when the cluster is no longer needed to ensure proper resource cleanup.

This method is automatically called when using context manager:

with ClusterDefinition("localhost", 3100).connect() as cluster:
    # Use the cluster...
# cluster.close() is automatically called here
Return type:

None