SyncTransactionalSession

class aerospike_sdk.sync.transactional_session.SyncTransactionalSession[source]

Bases: SyncSession

Sync context manager grouping operations into a multi-record transaction.

Every session API (query, upsert, insert, batch, …) works unchanged inside with; the active Txn is threaded onto every policy the builders hand to the PAC.

On clean exit the transaction commits; if an exception propagates out the transaction aborts. Explicit commit(), abort(), and rollback() (alias for abort) are 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()

See also

SyncSession.begin_transaction():

Preferred construction entry.

__init__(client, behavior)[source]

Construct via SyncSession.begin_transaction() rather than directly.

property txn: Txn

Return the active Txn.

Raises:

RuntimeError – If the session has not been entered (no active txn).

property active: bool

True when a transaction has been started and not yet finalized.

commit()[source]

Commit the transaction and return the server-reported status.

Return type:

CommitStatus

abort()[source]

Abort the transaction and return the server-reported status.

Return type:

AbortStatus

rollback()[source]

Alias for abort().

Return type:

AbortStatus