Coming from FreeRedis
Move FreeRedis.RedisClient callers to a long-lived RespireClient and await commands throughout
the call chain. Respire has no synchronous command API. Keep the same Redis keys and wire values
during a gradual rollout; compare serialization and expiry behavior before switching writers.
Respire targets .NET 10 and .NET 11; applications on .NET Framework must retarget before migrating.
The FreeRedis column uses the API documented in its upstream README.
Concepts and common calls
Here cli is a FreeRedis client, client is the unprefixed Respire root client, and redis
is that client or a key-prefixed view. Search commands require the unprefixed root client;
key-prefixed views reject them. Preserve physical document prefixes (for example, app:product:)
in the index definition's Prefixes instead.
| FreeRedis | Respire | Migration detail |
|---|---|---|
new RedisClient(connectionString) | await RespireClient.ConnectAsync(options) | Translate configuration; do not copy pool settings blindly. |
cli.GetDatabase(n) | A client with RespireOptions.Database = n | Database selection is fixed for the client's lifetime. |
prefix=app: | client.WithKeyPrefix("app:") | Pass logical keys without adding the prefix again. |
cli.Set(key, value) | await redis.Strings.SetAsync(key, value) | A plain SET clears an existing expiry. |
cli.Get(key) | await redis.Strings.GetStringAsync(key) | Missing strings return null. |
cli.IncrBy(key, 10) | await redis.Strings.IncrementAsync(key, 10) | Returns the new integer value. |
cli.Del(key) | await redis.Keys.DeleteAsync(key) | Returns the number deleted. |
cli.StartPipe() / pipe.EndPipe() | redis.CreateBatch() / await batch.ExecuteAsync() | Retain typed pendings; read them only after execution. |
cli.Multi() / tran.Exec() | redis.CreateTransaction() / await transaction.CommitAsync() | A transaction is atomic; a batch is not. |
cli.Subscribe(channel, ondata) | await redis.SubscribeAsync(channel) | Replace the callback with await foreach; dispose the subscription. |
cli.Publish(channel, payload) | await redis.PublishAsync(channel, payload) | Channels are separate from key prefixes. |
cli.FtSearch(...).Execute() | await client.Search.SearchAsync(index, query) | Use the unprefixed root client. Install Respire.Search and import using Respire.Search;; query is a RespireSearchQuery. Translate the query and result projection; see the complete module example. |
Connection, prefixes, and pipelining
dotnet add package Respire
This replaces a FreeRedis client configured with database 13 and the prefix app: on a
standalone server. Own the connection at application scope, rather than creating one per request.
using Respire;
await using var client = await RespireClient.ConnectAsync(new RespireOptions
{
Endpoints = [new("localhost", 6379)],
Database = 13,
});
var redis = client.WithKeyPrefix("app:");
await redis.Strings.SetAsync("name", "Ada", expiry: TimeSpan.FromMinutes(1));
string? name = await redis.Strings.GetStringAsync("name");
await using var batch = redis.CreateBatch();
var visits = batch.Increment("visits", 10);
var storedName = batch.GetString("name");
await batch.ExecuteAsync();
Console.WriteLine($"{storedName.Result}: {visits.Result}");
Concurrent individual commands are automatically pipelined. Explicit batches return typed
RespirePending<T> values rather than an object[]; read their .Result after executing the
batch. For Multi / Exec callers, use the same queue methods on a transaction and
commit it, as shown in the CSRedisCore transaction example.
Replace subscription callbacks
The subscription is active when SubscribeAsync completes. This bounded example publishes one
message and stops after receiving it; a service should use its shutdown token for the consumer.
using Respire;
await using var redis = await RespireClient.ConnectAsync("localhost:6379");
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(10));
await using var subscription = await redis.SubscribeAsync(
"migration-events", cancellationToken: timeout.Token);
await redis.PublishAsync("migration-events", "hello", timeout.Token);
await foreach (var message in subscription.WithCancellation(timeout.Token))
{
if (message.Kind == RespireMessageKind.Gap)
{
Console.Error.WriteLine($"Reload authoritative state after a delivery gap: {message.Gap}");
continue;
}
Console.WriteLine(message.Text);
break;
}
Differences to check before switching
- Configuration: FreeRedis pool sizes, send/receive timeouts, retries, and database leases
do not map one for one to a multiplexed Respire connection. Use
connection options,
CommandTimeout, and an explicit retry policy. Configure Cluster or Sentinel deliberately; Cluster uses database 0. Review replica-read policy rather than assuming the old constructor's routing. - Serialization: FreeRedis's
Serialize/Deserializedelegates are not Respire options. Keep pre-serialized values as strings or bytes, or configure a matching serializer. Test old payloads, nulls, missing keys, and non-UTF-8 values before adopting typed reads.GetAsync<int>returns the default for a missing key;TryGetAsync<T>distinguishes absence from a stored default. - Pub/sub: subscription disposal is asynchronous; use
await using. A slow consumer can overflow its buffer and receive a gap marker. Pub/sub does not provide durable delivery. - Modules: FreeRedis Search builders and document-repository attributes are not compatible
with Respire's types. Rebuild mappings with Search or
generated schemas. Use
Respire.Json,Respire.TimeSeries, andRespire.Probabilisticfor their respective server commands; see the module migration example. Installing a client package does not add server capabilities. - Higher-level helpers:
SubscribeList,SubscribeStream, and delay queues need a behavior review, including acknowledgement and retry rules. Start with blocking queues, stream workers, or job queues; do not assume their stored metadata is interchangeable. Client-side caching also needs its own Respire configuration.
For atomic operations and optimistic concurrency, see batches and transactions.