Skip to main content

Grant-ZrLease

Creates a new lease with a time-to-live and returns its lease id. Items attached to the lease expire when it is not kept alive.

Syntax

Grant-ZrLease -TimeToLive <TimeSpan> [-ConnectionString <string>] [-StoreName <string>] [-Endpoints <string[]>] [-TimeoutSec <int>]

Description

Grant-ZrLease grants a fresh lease on the connected Zaris store that lives for the given -TimeToLive and returns the generated lease id. Keys written under the lease (for example with Set-ZrItem -LeaseId) are removed automatically when the lease expires unless it is kept alive with Refresh-ZrLease. Leases are used to build temporary-ownership patterns such as distributed locks, leader election, and coordinated cleanup.

The cmdlet requires an active connection (Connect-ZrStore) or a one-shot independent connection supplied through -StoreName and -Endpoints.

Parameters

ParameterTypeRequiredDescription
-TimeToLiveTimeSpanYesThe lifetime of the lease before it expires unless kept alive. Named (not positional).
-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 operate on for a one-shot independent connection instead of the active Connect-ZrStore context. Belongs to the Independent parameter set; use together with -Endpoints.
-EndpointsString[]NoOne or more store node endpoints (host:port) for an independent connection. Only the first endpoint is used as the seed. Ignored when a Connect-ZrStore session is active.
-TimeoutSecInt32NoConnection timeout, in seconds, for an independent connection. Range 1–120. Default 5.

Returns an object with LeaseId, TtlSeconds, Success, and Error.

Examples

Grant a lease that expires after 30 seconds unless it is kept alive:

Grant-ZrLease -TimeToLive (New-TimeSpan -Seconds 30)

Grant a five-minute lease and capture its id for later use:

$lease = (Grant-ZrLease -TimeToLive (New-TimeSpan -Minutes 5)).LeaseId