Table of Contents

Method TryCreateAsync

Namespace
NATS.Client.KeyValueStore
Assembly
NATS.Client.KeyValueStore.dll

TryCreateAsync<T>(string, T, INatsSerialize<T>?, CancellationToken)

Tries to create a new entry in the bucket only if it doesn't exist

public ValueTask<NatsResult<ulong>> TryCreateAsync<T>(string key, T value, INatsSerialize<T>? serializer = null, CancellationToken cancellationToken = default)

Parameters

key string

Key of the entry

value T

Value of the entry

serializer INatsSerialize<T>

Serializer to use for the message type.

cancellationToken CancellationToken

A CancellationToken used to cancel the API call.

Returns

ValueTask<NatsResult<ulong>>

A NatsResult object representing the revision number of the created entry or an error.

Type Parameters

T

Serialized value type

Remarks

Use this method to avoid exceptions

TryCreateAsync<T>(string, T, TimeSpan, INatsSerialize<T>?, CancellationToken)

Tries to create a new entry in the bucket only if it doesn't exist

public ValueTask<NatsResult<ulong>> TryCreateAsync<T>(string key, T value, TimeSpan ttl, INatsSerialize<T>? serializer = null, CancellationToken cancellationToken = default)

Parameters

key string

Key of the entry

value T

Value of the entry

ttl TimeSpan

Time to live for the entry (requires the LimitMarkerTTL to be set to true). For a key that should never expire, use the MaxValue constant. This feature is only available on NATS server v2.11 and later.

serializer INatsSerialize<T>

Serializer to use for the message type.

cancellationToken CancellationToken

A CancellationToken used to cancel the API call.

Returns

ValueTask<NatsResult<ulong>>

A NatsResult object representing the revision number of the created entry or an error.

Type Parameters

T

Serialized value type

Remarks

Use this method to avoid exceptions