Thus, one can use Garnet with unmodified Redis clients available in
most programming languages, for example, with StackExchange.Redis in
C#.
As far as I know, there is no Garnet library for Aspire, but it can be used by specifying the image:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache", port: 6379).WithImage("ghcr.io/microsoft/garnet")
When starting from the aspire starter template, I tried to add distributed caching to the "Counter" page:
protected override async Task OnInitializedAsync()
{
var bytes = await cache.GetAsync("counter");
if (bytes != null)
{
currentCount = BitConverter.ToInt32(bytes);
}
}
public async Task IncrementCount()
{
currentCount++;
await cache.SetAsync("counter", BitConverter.GetBytes(currentCount));
}
Works seamlessly with Redis. However, it fails with Garnet:
StackExchange.Redis.RedisServerException: ERR unknown command
at StackExchange.Redis.RedisDatabase.ScriptEvaluateAsync(String script,
RedisKey[] keys, RedisValue[] values, CommandFlags flags) in
/_/src/StackExchange.Redis/RedisDatabase.cs:line 1551
at Microsoft.Extensions.Caching.StackExchangeRedis.RedisCache.SetAsync(String
key, Byte[] value, DistributedCacheEntryOptions options,
CancellationToken token)
at AspireAppHybridCache.Web.Components.Pages.Counter.IncrementCount() in
D:\Workspace\playground\AspireAppHybridCache\AspireAppHybridCache.Web\Components\Pages\Counter.razor:line
28
Am I missing something essential here?
0 comments:
Post a Comment
Thanks