Skip to main content

Increment-ZrCounter

Atomically increases a distributed counter by a positive amount and returns its new value. Creates the counter if it does not exist.

Syntax

Increment-ZrCounter [-Key] <string> [[-Delta] <long>] [-ConnectionString <string>] [-StoreName <string>] [-Endpoints <string[]>] [-TimeoutSec <int>]

Description

Increment-ZrCounter adds -Delta to the atomic counter stored under -Key via the store's counter API (Counters.AddAsync) and returns the resulting value. The operation is applied atomically on the owning node, so concurrent increments from multiple clients remain consistent. If the counter does not yet exist it is created starting from the applied delta.

-Delta defaults to 1 and must be a positive value (1 through Int64.MaxValue); to reduce a counter use Decrement-ZrCounter.md. The command runs against the active Connect-ZrStore session, or against a one-shot connection when -StoreName and -Endpoints are supplied.

Parameters

ParameterTypeRequiredDescription
-KeyStringYesKey identifying the counter to increment. Positional (position 0). Must not be null or empty.
-DeltaInt64NoPositive amount to add to the counter. Positional (position 1). Range 1 to Int64.MaxValue. Default 1.
-ConnectionStringStringNoConnect via a Zaris connection string, e.g. zaris://host:7861/store; an alternative to -StoreName + -Endpoints for a one-shot connection. Ignored when a Connect-ZrStore session is active.
-StoreNameStringNoStore to target when using an independent (one-shot) connection instead of the active session. Requires -Endpoints.
-EndpointsString[]NoOne or more node endpoints (host:port) for an independent connection. Ignored when a Connect-ZrStore session is active.
-TimeoutSecInt32NoConnection timeout in seconds (1–120) for an independent connection. Default 5.

Examples

Increase a counter by the default of 1:

Increment-ZrCounter -Key "orders:processed"

Increase a counter by 10:

Increment-ZrCounter -Key "orders:processed" -Delta 10