SyncTransactionalSession¶
- class aerospike_sdk.sync.transactional_session.SyncTransactionalSession[source]¶
Bases:
SyncSessionSync context manager that groups operations into a multi-record transaction.
Subclasses
SyncSession, so every session API (query,upsert,insert,batch, …) works unchanged insidewith; the underlying asyncTransactionalSessionthreads the activeTxnonto every policy the builders hand to the PAC — the user never touches a policy.On clean exit the transaction is committed; if an exception propagates out of the block the transaction is aborted. Explicit
commit(),abort(), androllback()(alias forabort) are also available for manual control.Example
>>> with client.create_session().begin_transaction() as tx: ... tx.upsert(accounts.id("A")).bin("balance").set_to(100).execute() ... tx.upsert(accounts.id("B")).bin("balance").set_to(200).execute() # Auto-committed on clean exit; auto-aborted on exception.
See also
aerospike_sdk.sync.session.SyncSession.begin_transaction()aerospike_sdk.sync.cluster.Cluster.create_transactional_session()aerospike_sdk.aio.transactional_session.TransactionalSession- __init__(async_txn_session, loop_manager)[source]¶
Wrap
async_txn_session; useSyncSession.begin_transaction()instead.- Parameters:
async_txn_session (
TransactionalSession) – Underlying asyncTransactionalSessionsharing the same client and behavior.loop_manager (
_EventLoopManager) – Loop manager shared with the parentSyncClient.
Note
Application code should not construct
SyncTransactionalSessiondirectly; callSyncSession.begin_transaction()orCluster.create_transactional_session()instead.
- property txn: Txn¶
Return the underlying
Txn.- Raises:
RuntimeError – If the session has not been entered (no active txn).
- Returns:
The active
Txn.
- property active: bool¶
Truewhen a transaction has been started and not yet finalized.- Returns:
Whether a transaction is currently active on this session.
- commit()[source]¶
Commit the transaction and return the server-reported status.
- Raises:
RuntimeError – If the session has no active transaction.
- Return type:
CommitStatus- Returns:
CommitStatusreported by the server.
See also
abort(): Undo the transaction instead of committing.
- abort()[source]¶
Abort the transaction and return the server-reported status.
- Raises:
RuntimeError – If the session has no active transaction.
- Return type:
AbortStatus- Returns:
AbortStatusreported by the server.
See also
commit(): Persist the transaction instead of aborting.rollback(): Alias for this method.