ZorgoZ
ZorgoZ

Reputation: 3567

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?

Upvotes: 3

Views: 2089

Answers (2)

Guy Royse
Guy Royse

Reputation: 4332

I don't think you are missing anything.

That ERR unknown command is almost certainly coming from Garnet as that's the same message that Redis reports for unknown commands.

Garnet doesn't support the full set of Redis commands—I think it only supports about a third of them—and it looks like StackExchange.Redis is using one outside of that third.

Upvotes: 4

slorello
slorello

Reputation: 1159

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.

Upvotes: 4

Related Questions