TransactionalSession¶
- class aerospike_sdk.aio.transactional_session.TransactionalSession[source]¶
Bases:
SessionAsync context manager that groups operations into a multi-record transaction.
Subclasses
Session, so every session API (query,upsert,insert,batch, …) works unchanged insideasync with; builders capture the activeTxnviaget_current_transaction()and thread it onto every policy they 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
>>> async with client.create_session().begin_transaction() as tx: ... await tx.upsert(accounts.id("A")).bin("balance").set_to(100).execute() ... await tx.upsert(accounts.id("B")).bin("balance").set_to(200).execute() # Auto-committed on clean exit; auto-aborted on exception.
See also
aerospike_sdk.aio.session.Session.begin_transaction()aerospike_sdk.aio.client.Client.transaction_session()- __init__(client, behavior=None)[source]¶
Create a transactional session; prefer
Session.begin_transaction().- Parameters:
Note
Application code should not construct
TransactionalSessiondirectly; callSession.begin_transaction()orClient.transaction_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.
- async 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.
- async 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.