Method IncrementAsync
IncrementAsync(string, long, TimeSpan, CancellationToken)
Adds an amount to the counter under a key and returns the new count. A key without a value counts from 0. Every increment sets the counter to expire after the lifetime, counted from the increment.
Declaration
public ValueTask<long> IncrementAsync(string key, long amount, TimeSpan lifetime, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key. |
| long | amount | The amount to add, which can be negative. |
| TimeSpan | lifetime | How long the counter is kept after this increment. Must be positive. |
| CancellationToken | cancellationToken | A token to cancel the operation. |
Returns
| Type | Description |
|---|---|
| ValueTask<long> |
Implements
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | The key holds a value that is not a count. |