Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is GARNET really a drop-in replacement for REDIS?

I am experimenting with ASPIRE and GARNET, the latter replacing REDIS. According to the documentation:

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?

like image 415
ZorgoZ Avatar asked Oct 16 '25 04:10

ZorgoZ


1 Answers

Garnet does not support Lua Scripting, and much of the ecosystem for caching/session management in .NET is built on top of the Lua Scripting engine within Redis. That's why you're getting the ERR unknown command - the EVAL / EVALSHA commands are not implemented.

There's been some work to remove the dependency on LUA for .NET 9 as it really doesn't seem to be necessary for the logic within the IDistributedCache.

Garnet is a RESP(Redis Serialization Protocol) compatible server that can be used for some of the same tasks as Redis. But calling it a drop-in replacement for Redis would clearly be an overstatement.

like image 192
slorello Avatar answered Oct 18 '25 20:10

slorello



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!