Sync Cluster¶
- class aerospike_sdk.sync.cluster.Cluster[source]¶
Bases:
objectSynchronous cluster handle from
sync.cluster_definition.ClusterDefinition.connect.Mirrors
Clusterbut usesSyncClientandSyncSession.Example:
with ClusterDefinition("localhost", 3100).connect() as cluster: session = cluster.create_session(Behavior.DEFAULT)
See also
- __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
SyncSessionfor 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 toDEFAULT.- Return type:
- Returns:
A new sync session bound to this cluster’s client.
See also
- create_transactional_session(behavior=None)[source]¶
Return a
SyncTransactionalSessionfor a multi-record transaction.Equivalent to
create_session(behavior).begin_transaction()— the returned context manager allocates a freshTxnon 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]) – OptionalBehaviorfor operations inside the transaction. Defaults toBehavior.DEFAULTwhen omitted.- Return type:
- Returns:
A
SyncTransactionalSessionbound 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:
- 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: