Options
Clustron DKV allows you to control operation behavior using options.
Options extend the API without changing how you call it.
Why Options Matterβ
Basic usage is simple:
await client.PutAsync("key", "value");
But real applications need more control:
- Conditional writes
- Expiration (TTL)
- Indexing for search
- Ownership via leases
- Concurrency control
Options enable all of this.
Put Optionsβ
PutOptions controls how data is written.
You can create options using helper methods:
var opts = Put.WithEntity("customer")
.WithLabel("city", "London")
.WithTtl(TimeSpan.FromMinutes(5));
await client.PutAsync("cust:1", customer, opts);
Core Capabilitiesβ
Entity (Required for Search)β
Put.WithEntity("customer")
- Defines logical grouping
- Enables indexing
- Required for search queries
Labels (Indexed Metadata)β
.WithLabel("city", "London")
.WithLabel("age", "30")
- Adds searchable fields
- Used in
SearchQuery
Indexed vs Non-Indexed Labelsβ
.WithLabel("debug", "value", indexed: false)
indexed: true(default) β searchableindexed: falseβ metadata only
TTL (Time-to-Live)β
Put.WithTtl(TimeSpan.FromMinutes(10))
- Automatically removes key after duration
- Used for expiration (not ownership)
Lease Attachmentβ
Put.WithLease(lease.Id)
or
await client.PutAsync("worker:1", "active",
Put.WithEntity("worker").WithLease(lease.Id));
- Associates key with a lease
- Key is removed when lease expires
Lock Attachmentβ
Put.WithLock(lockHandle)
- Ensures operation is performed under lock
- Used for safe coordination
Conditional Writesβ
IfAbsentβ
Put.IfAbsent()
or chained:
Put.WithEntity("order").IfAbsent()
- Only writes if key does not exist
- Prevents overwriting
IfMatch (Optimistic Concurrency)β
Put.WithIfMatch(version)
- Writes only if version matches
- Prevents overwriting newer data
Content Typeβ
Put.WithContentType("application/json")
- Describes stored data format
- Useful for interoperability
Combining Optionsβ
All options are composable:
var opts = Put.WithEntity("order")
.WithLabel("status", "pending")
.WithTtl(TimeSpan.FromMinutes(5))
.IfAbsent();
await client.PutAsync("order:1", order, opts);
Metadata Model (Conceptual)β
Internally, options build metadata:
Key β Value
β Entity
β Labels
β TTL
β Lease
β Lock
This metadata drives:
- Search
- Expiration
- Coordination
When to Use Which Optionβ
| Requirement | Option |
|---|---|
| Search / Query | Entity + Labels |
| Expiration | TTL |
| Ownership | Lease |
| Concurrency control | IfMatch |
| Prevent overwrite | IfAbsent |
| Coordination | Lock |
Important Notesβ
- Options are optional but powerful
- Labels are required for search
- TTL and Lease serve different purposes
- Conditional options prevent data corruption
Best Practicesβ
- Always define Entity + Labels for queryable data
- Use TTL for data expiration
- Use Lease for ownership and lifecycle
- Use IfMatch for safe updates
- Keep option usage consistent across your system
Key Takeawayβ
Options = Control over behavior without changing API shape
They are the foundation of Clustronβs flexibility.
Whatβs Nextβ
π Continue to Error Handling to handle failures safely