Table of Contents

Interface ITransactions

Namespace
Apache.Ignite.Transactions
Assembly
Apache.Ignite.dll

Ignite transactions API.

public interface ITransactions

Methods

BeginAsync()

Starts a new transaction.

ValueTask<ITransaction> BeginAsync()

Returns

ValueTask<ITransaction>

A ValueTask representing the asynchronous operation.

BeginAsync(TransactionOptions)

Starts a new transaction.

ValueTask<ITransaction> BeginAsync(TransactionOptions options)

Parameters

options TransactionOptions

Transaction options.

Returns

ValueTask<ITransaction>

A ValueTask representing the asynchronous operation.

RunInTransactionAsync(Func<ITransaction, Task>, TransactionOptions)

Runs the specified function within a transaction. The transaction is committed automatically.

The transaction is rolled back if the function throws an exception.
const decimal amount = 1000;
IKeyValueView<int, Account> view = Table.GetKeyValueView<int, Account>();
decimal resultAmount = await Client.Transactions.RunInTransactionAsync(async tx =>
{
    var acc1 = await view.GetAsync(tx, 1);
    var acc2 = await view.GetAsync(tx, 2);
    acc1.Value.Amount += amount;
    acc2.Value.Amount -= amount;
    await view.PutAsync(tx, 1, acc1.Value);
    await view.PutAsync(tx, 2, acc2.Value);
    return acc1.Value.Amount;
});
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "False positive, ConfigureAwait is present.")]
Task RunInTransactionAsync(Func<ITransaction, Task> func, TransactionOptions options = default)

Parameters

func Func<ITransaction, Task>

Function.

options TransactionOptions

Transaction options.

Returns

Task

Function result.

RunInTransactionAsync<T>(Func<ITransaction, Task<T>>, TransactionOptions)

Runs the specified function within a transaction. The transaction is committed automatically.

The transaction is rolled back if the function throws an exception.
const decimal amount = 1000;
IKeyValueView<int, Account> view = Table.GetKeyValueView<int, Account>();
await Client.Transactions.RunInTransactionAsync(async tx =>
{
    var acc1 = await view.GetAsync(tx, 1);
    var acc2 = await view.GetAsync(tx, 2);
    acc1.Value.Amount += amount;
    acc2.Value.Amount -= amount;
    await view.PutAsync(tx, 1, acc1.Value);
    await view.PutAsync(tx, 2, acc2.Value);
});
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "False positive, ConfigureAwait is present.")]
Task<T> RunInTransactionAsync<T>(Func<ITransaction, Task<T>> func, TransactionOptions options = default)

Parameters

func Func<ITransaction, Task<T>>

Function.

options TransactionOptions

Transaction options.

Returns

Task<T>

Function result.

Type Parameters

T

Result type.