Get started with the Garnet integration
Bu içerik henüz dilinizde mevcut değil.
Garnet is a high-performance cache-store from Microsoft Research that complies with the Redis serialization protocol (RESP). The Garnet integration enables you to connect to existing Garnet instances, or create new instances from Aspire with the ghcr.io/microsoft/garnet container image.
In this introduction, you’ll see how to install and use the Aspire Garnet integrations in a simple configuration. If you already have this knowledge, see Garnet hosting integration for full reference details.
Set up hosting integration
Section titled “Set up hosting integration”To begin, install the Aspire Garnet hosting integration in your Aspire AppHost project:
aspire add garnetAspire CLI etkileşimlidir; istendiğinde uygun sonucu seçin:
Select an integration to add:
> garnet (Aspire.Hosting.Garnet)> Other results listed as selectable options...#:package Aspire.Hosting.Garnet@*<PackageReference Include="Aspire.Hosting.Garnet" Version="*" />Next, in the AppHost project, create instances of Garnet resources and pass them to the consuming client projects:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddGarnet("cache");
var myService = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);
builder.Build().Run();When Aspire adds a container image to the AppHost, it creates a new Garnet instance on your local machine.
Set up client integration
Section titled “Set up client integration”Garnet is Redis-compatible, so you use the same Redis client packages. To get started, install the package:
dotnet add package Aspire.StackExchange.Redis#:package Aspire.StackExchange.Redis@*<PackageReference Include="Aspire.StackExchange.Redis" Version="*" />In the Program.cs file of your client-consuming project, call the AddRedisClient extension method to register an IConnectionMultiplexer:
builder.AddRedisClient(connectionName: "cache");You can then retrieve the IConnectionMultiplexer instance using dependency injection:
public class ExampleService(IConnectionMultiplexer connectionMux){ // Use connection multiplexer...}