Skip to main content

First operations

This article covers the three key-value operations you use most with Clustron Zaris: storing a value, reading it back, and removing it. Together they follow a simple put, get, delete pattern.

The same API works in both in-process and distributed modes, so the code here runs unchanged whichever mode your store uses.

Prerequisites

You need a running store and a connected client. If you don't have one yet, get a client in Run in-process or Create your first store. The examples below assume a client variable from those steps.

Put a value

Store a value for a key with PutAsync. If the key already exists, its value is overwritten.

await client.PutAsync("hello", "world");

Get a value

Read a value with GetAsync, passing the type you expect. The call returns a result whose IsSuccess property tells you whether the key was found, and whose Value property holds the value when it was.

var result = await client.GetAsync<string>("hello");

if (result.IsSuccess)
{
Console.WriteLine(result.Value);
}
else
{
Console.WriteLine("Key not found");
}

Delete a value

Remove a key and its value with DeleteAsync.

await client.DeleteAsync("hello");

Handle results

Most operations return a KvResult. Check its IsSuccess property to confirm the operation worked, and read Error when it didn't. This lets you handle failures instead of assuming every call succeeds.

var result = await client.PutAsync("key", "value");

if (!result.IsSuccess)
{
Console.WriteLine(result.Error);
}

Things to know

A few rules apply to every operation:

  • Keys are strings.
  • Values are serialized automatically.
  • All operations are asynchronous, so await them.
  • The same API works in both in-process and distributed modes.

Next steps

For complete working examples, see the Zaris samples repository:

https://github.com/Clustron/zaris/tree/main/Samples