C# SDK
Installation
Add via NuGet:
dotnet add package TollMeshCache
Or in csproj:
<ItemGroup>
<PackageReference Include="TollMeshCache" Version="1.0.0" />
</ItemGroup>
Quick Start
using TollMeshCache;
using System;
using System.Threading.Tasks;
class Program {
static async Task Main() {
var config = new ClientConfig {
Host = "localhost",
Port = 8080
};
using var client = new Client(config);
// Rate limiting
var result = await client.ConsumeAsync(
"user-123",
100,
TimeSpan.FromMinutes(1)
);
if (result.Ok) {
Console.WriteLine("Request allowed");
}
}
}
Features
- ✅ Native async/await support
- ✅ Multi-target (.NET 6.0, 7.0, 8.0, Standard 2.1)
- ✅ Strong typing with generics
- ✅ HttpClient connection pooling
- ✅ Comprehensive error handling
API Reference
This section covers rate limiting, replay protection, and caching. This SDK also has full, identical-API support for Job Queues, Sorted Sets, Streams, Pub/Sub, Transactions, Persistence, Pipelines, WASM Scripting, Search, Ranking, and Metrics — see the full API Reference for all of them, with live-verified examples.
Rate Limiting
var result = await client.ConsumeAsync(key, limit, window);
// Fields: Ok, Remaining, ResetAt
Replay Protection
var result = await client.SeenAsync(key, ttl);
// Field: Seen
Caching
await client.CacheSetAsync(namespace, key, value, ttl);
var result = await client.CacheGetAsync(namespace, key);
// Fields: Value, Exists
Health
var health = await client.HealthAsync();
var peers = await client.GetPeersAsync();
Error Handling
using TollMeshCache;
try {
var result = await client.ConsumeAsync("key", 100, TimeSpan.FromMinutes(1));
} catch (RateLimitException e) {
Console.WriteLine($"Rate limited: {e.Message}");
} catch (TollMeshException e) {
Console.WriteLine($"Error {e.ErrorCode}: {e.Message}");
}
Configuration
var config = new ClientConfig {
Host = "localhost",
Port = 8080,
Timeout = TimeSpan.FromSeconds(5),
VerifySsl = true,
ApiKey = "optional-key",
HttpScheme = "http",
MaxRetries = 3,
RetryBackoff = 1.0,
ConnectionPoolSize = 10
};
using var client = new Client(config);
Testing
dotnet test
Examples
See examples/ for:
RateLimitingExample.cs- Rate limiting patterns
Run example:
dotnet run --project sdks/csharp/examples
Multi-targeting
The SDK targets multiple .NET versions for compatibility:
- net8.0 - Latest .NET 8
- net7.0 - .NET 7
- net6.0 - .NET 6
- netstandard2.1 - .NET Standard 2.1 (for .NET Framework)