IReliableDictionary<TKey,TValue>.AddOrUpdateAsync Method

Definition

Overloads

AddOrUpdateAsync(ITransaction, TKey, Func<TKey,TValue>, Func<TKey,TValue,TValue>)

Uses the specified functions to add a key/value pair to the Reliable Dictionary if the key does not already exist, or to update a key/value pair in the Reliable Dictionary if the key already exists.

AddOrUpdateAsync(ITransaction, TKey, TValue, Func<TKey,TValue,TValue>)

Adds a key/value pair to the Reliable Dictionary if the key does not already exist, or updates a key/value pair in the Reliable Dictionary by using the specified function if the key already exists.

AddOrUpdateAsync(ITransaction, TKey, Func<TKey,TValue>, Func<TKey,TValue,TValue>, TimeSpan, CancellationToken)

Uses the specified functions to add a key/value pair to the Reliable Dictionary if the key does not already exist, or to update a key/value pair in the Reliable Dictionary if the key already exists.

AddOrUpdateAsync(ITransaction, TKey, TValue, Func<TKey,TValue,TValue>, TimeSpan, CancellationToken)

Adds a key/value pair to the Reliable Dictionary if the key does not already exist, or updates a key/value pair in the Reliable Dictionary by using the specified function if the key already exists.

AddOrUpdateAsync(ITransaction, TKey, Func<TKey,TValue>, Func<TKey,TValue,TValue>)

Uses the specified functions to add a key/value pair to the Reliable Dictionary if the key does not already exist, or to update a key/value pair in the Reliable Dictionary if the key already exists.

public System.Threading.Tasks.Task<TValue> AddOrUpdateAsync (Microsoft.ServiceFabric.Data.ITransaction tx, TKey key, Func<TKey,TValue> addValueFactory, Func<TKey,TValue,TValue> updateValueFactory);
abstract member AddOrUpdateAsync : Microsoft.ServiceFabric.Data.ITransaction * 'Key * Func<'Key, 'Value (requires 'Key :> IComparable<'Key> and 'Key :> IEquatable<'Key>)> * Func<'Key, 'Value, 'Value (requires 'Key :> IComparable<'Key> and 'Key :> IEquatable<'Key>)> -> System.Threading.Tasks.Task<'Value>
Public Function AddOrUpdateAsync (tx As ITransaction, key As TKey, addValueFactory As Func(Of TKey, TValue), updateValueFactory As Func(Of TKey, TValue, TValue)) As Task(Of TValue)

Parameters

tx
ITransaction

Transaction to associate this operation with.

key
TKey

The key to be added or whose value should be updated.

addValueFactory
Func<TKey,TValue>

The function used to generate a value for an absent key.

updateValueFactory
Func<TKey,TValue,TValue>

The function used to generate a new value for an existing key based on the key's existing value.

Returns

Task<TValue>

Task that represents the asynchronous add or update operation. The task result is the new value for the key. This will be either the result of addValueFactory (if the key was absent) or the result of updateValueFactory (if the key was present).

Exceptions

tx is null, or key is null or cannot be serialized, or addValueFactory is null, or updateValueFactory is null.

The operation failed to complete within the default timeout.

The exception that is thrown when the IReliableDictionary<TKey,TValue> is not in Primary.

The transaction has been internally faulted by the system. Retry the operation on a new transaction

Thrown when a method call is invalid for the object's current state. Example, transaction used is already terminated: committed or aborted by the user. If this exception is thrown, it is highly likely that there is a bug in the service code of the use of transactions.

Indicates that the Reliable Dictionary is closed or deleted.

Applies to

AddOrUpdateAsync(ITransaction, TKey, TValue, Func<TKey,TValue,TValue>)

Adds a key/value pair to the Reliable Dictionary if the key does not already exist, or updates a key/value pair in the Reliable Dictionary by using the specified function if the key already exists.

public System.Threading.Tasks.Task<TValue> AddOrUpdateAsync (Microsoft.ServiceFabric.Data.ITransaction tx, TKey key, TValue addValue, Func<TKey,TValue,TValue> updateValueFactory);
abstract member AddOrUpdateAsync : Microsoft.ServiceFabric.Data.ITransaction * 'Key * 'Value * Func<'Key, 'Value, 'Value (requires 'Key :> IComparable<'Key> and 'Key :> IEquatable<'Key>)> -> System.Threading.Tasks.Task<'Value>
Public Function AddOrUpdateAsync (tx As ITransaction, key As TKey, addValue As TValue, updateValueFactory As Func(Of TKey, TValue, TValue)) As Task(Of TValue)

Parameters

tx
ITransaction

Transaction to associate this operation with.

key
TKey

The key to be added or whose value should be updated.

addValue
TValue

The value to be added for an absent key. The value can be null for reference types.

updateValueFactory
Func<TKey,TValue,TValue>

The function used to generate a new value for an existing key based on the key's existing value.

Returns

Task<TValue>

Task that represents the asynchronous add or update operation. The task result is the new value for the key. This will be either addValue (if the key was absent) or the result of updateValueFactory (if the key was present).

Exceptions

tx is null, or key is null or cannot be serialized, or updateValueFactory is null.

The operation failed to complete within the default timeout.

The exception that is thrown when the IReliableDictionary<TKey,TValue> is not in Primary.

The transaction has been internally faulted by the system. Retry the operation on a new transaction

Thrown when a method call is invalid for the object's current state. Example, transaction used is already terminated: committed or aborted by the user. If this exception is thrown, it is highly likely that there is a bug in the service code of the use of transactions.

Indicates that the Reliable Dictionary is closed or deleted.

Applies to

AddOrUpdateAsync(ITransaction, TKey, Func<TKey,TValue>, Func<TKey,TValue,TValue>, TimeSpan, CancellationToken)

Uses the specified functions to add a key/value pair to the Reliable Dictionary if the key does not already exist, or to update a key/value pair in the Reliable Dictionary if the key already exists.

public System.Threading.Tasks.Task<TValue> AddOrUpdateAsync (Microsoft.ServiceFabric.Data.ITransaction tx, TKey key, Func<TKey,TValue> addValueFactory, Func<TKey,TValue,TValue> updateValueFactory, TimeSpan timeout, System.Threading.CancellationToken cancellationToken);
abstract member AddOrUpdateAsync : Microsoft.ServiceFabric.Data.ITransaction * 'Key * Func<'Key, 'Value (requires 'Key :> IComparable<'Key> and 'Key :> IEquatable<'Key>)> * Func<'Key, 'Value, 'Value (requires 'Key :> IComparable<'Key> and 'Key :> IEquatable<'Key>)> * TimeSpan * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Value>
Public Function AddOrUpdateAsync (tx As ITransaction, key As TKey, addValueFactory As Func(Of TKey, TValue), updateValueFactory As Func(Of TKey, TValue, TValue), timeout As TimeSpan, cancellationToken As CancellationToken) As Task(Of TValue)

Parameters

tx
ITransaction

Transaction to associate this operation with.

key
TKey

The key to be added or whose value should be updated.

addValueFactory
Func<TKey,TValue>

The function used to generate a value for an absent key.

updateValueFactory
Func<TKey,TValue,TValue>

The function used to generate a new value for an existing key based on the key's existing value.

timeout
TimeSpan

The amount of time to wait for the operation to complete before throwing a TimeoutException. Primarily used to prevent deadlocks. The default is 4 seconds.

cancellationToken
CancellationToken

The token to monitor for cancellation requests. The default is None.

Returns

Task<TValue>

Task that represents the asynchronous add or update operation. The task result is the new value for the key. This will be either the result of addValueFactory (if the key was absent) or the result of updateValueFactory (if the key was present).

Exceptions

tx is null, or key is null or cannot be serialized, or addValueFactory is null, or updateValueFactory is null.

timeout is negative.

The operation failed to complete within the given timeout.

The operation was canceled.

The exception that is thrown when the IReliableDictionary<TKey,TValue> is not in Primary.

The transaction has been internally faulted by the system. Retry the operation on a new transaction

Thrown when a method call is invalid for the object's current state. Example, transaction used is already terminated: committed or aborted by the user. If this exception is thrown, it is highly likely that there is a bug in the service code of the use of transactions.

Indicates that the Reliable Dictionary is closed or deleted.

Applies to

AddOrUpdateAsync(ITransaction, TKey, TValue, Func<TKey,TValue,TValue>, TimeSpan, CancellationToken)

Adds a key/value pair to the Reliable Dictionary if the key does not already exist, or updates a key/value pair in the Reliable Dictionary by using the specified function if the key already exists.

public System.Threading.Tasks.Task<TValue> AddOrUpdateAsync (Microsoft.ServiceFabric.Data.ITransaction tx, TKey key, TValue addValue, Func<TKey,TValue,TValue> updateValueFactory, TimeSpan timeout, System.Threading.CancellationToken cancellationToken);
abstract member AddOrUpdateAsync : Microsoft.ServiceFabric.Data.ITransaction * 'Key * 'Value * Func<'Key, 'Value, 'Value (requires 'Key :> IComparable<'Key> and 'Key :> IEquatable<'Key>)> * TimeSpan * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Value>
Public Function AddOrUpdateAsync (tx As ITransaction, key As TKey, addValue As TValue, updateValueFactory As Func(Of TKey, TValue, TValue), timeout As TimeSpan, cancellationToken As CancellationToken) As Task(Of TValue)

Parameters

tx
ITransaction

Transaction to associate this operation with.

key
TKey

The key to be added or whose value should be updated.

addValue
TValue

The value to be added for an absent key. The value can be null for reference types.

updateValueFactory
Func<TKey,TValue,TValue>

The function used to generate a new value for an existing key based on the key's existing value.

timeout
TimeSpan

The amount of time to wait for the operation to complete before throwing a TimeoutException. Primarily used to prevent deadlocks. The default is 4 seconds.

cancellationToken
CancellationToken

The token to monitor for cancellation requests. The default is None.

Returns

Task<TValue>

Task that represents the asynchronous add or update operation. The task result is the new value for the key. This will be either addValue (if the key was absent) or the result of updateValueFactory (if the key was present).

Exceptions

tx is null, or key is null or cannot be serialized, or updateValueFactory is null.

timeout is negative.

The operation failed to complete within the given timeout.

The operation was canceled.

The exception that is thrown when the IReliableDictionary<TKey,TValue> is not in Primary.

The transaction has been internally faulted by the system. Retry the operation on a new transaction

Thrown when a method call is invalid for the object's current state. Example, transaction used is already terminated: committed or aborted by the user. If this exception is thrown, it is highly likely that there is a bug in the service code of the use of transactions.

Indicates that the Reliable Dictionary is closed or deleted.

Applies to