Set-ZrCounter
Sets a distributed counter to an explicit absolute value, creating it if it does not yet exist. This overwrites any previous value rather than adjusting it.
Syntax
Set-ZrCounter [-Key] <string> [-Value] <long> [-ConnectionString <string>] [-StoreName <string>] [-Endpoints <string[]>] [-TimeoutSec <int>]
Description
Set-ZrCounter writes an absolute value to the atomic counter stored under -Key via the store's counter API (Counters.SetAsync). If the counter does not exist it is created; if it does exist its value is overwritten. Use this to seed or reset a counter — for relative changes use Increment-ZrCounter.md or Decrement-ZrCounter.md.
The counter API does not take a TTL, so counters set this way do not expire on their own. The command runs against the active Connect-ZrStore session, or against a one-shot connection when -StoreName and -Endpoints are supplied.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
-Key | String | Yes | Key identifying the counter to set. Positional (position 0). Must not be null or empty. |
-Value | Int64 | Yes | Absolute value to store in the counter. Positional (position 1). |
-ConnectionString | String | No | Connect 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. |
-StoreName | String | No | Store to target when using an independent (one-shot) connection instead of the active session. Requires -Endpoints. |
-Endpoints | String[] | No | One or more node endpoints (host:port) for an independent connection. Ignored when a Connect-ZrStore session is active. |
-TimeoutSec | Int32 | No | Connection timeout in seconds (1–120) for an independent connection. Default 5. |
Examples
Reset a counter to zero:
Set-ZrCounter -Key "orders:processed" -Value 0
Seed a quota counter using positional arguments:
Set-ZrCounter "api:quota:user123" 1000