Garnet hosting integration
Konten ini belum tersedia dalam bahasa Anda.
The Garnet hosting integration models a Garnet resource as the GarnetResource type. To access this type and APIs, add the 📦 Aspire.Hosting.Garnet NuGet package in your AppHost project:
aspire add garnetAspire CLI interaktif; pilih hasil pencarian yang sesuai saat diminta:
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="*" />Add Garnet resource
Section titled “Add Garnet resource”In your AppHost project, call AddGarnet on the builder instance to add a Garnet resource:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddGarnet("cache");
var myService = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);When Aspire adds a container image to the AppHost, it creates a new Garnet instance on your local machine.
Add Garnet resource with data volume
Section titled “Add Garnet resource with data volume”To add a data volume to the Garnet resource, call the WithDataVolume method:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddGarnet("cache") .WithDataVolume(isReadOnly: false);
var myService = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);The data volume is used to persist the Garnet data outside the lifecycle of its container. The data volume is mounted at the /data path in the Garnet container.
Add Garnet resource with data bind mount
Section titled “Add Garnet resource with data bind mount”To add a data bind mount to the Garnet resource, call the WithDataBindMount method:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddGarnet("cache") .WithDataBindMount( source: @"C:\Garnet\Data", isReadOnly: false);
var myService = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);Add Garnet resource with persistence
Section titled “Add Garnet resource with persistence”To add persistence to the Garnet resource, call the WithPersistence method with either the data volume or data bind mount:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddGarnet("cache") .WithDataVolume() .WithPersistence( interval: TimeSpan.FromMinutes(5), keysChangedThreshold: 100);
var myService = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);The preceding code adds persistence to the Garnet resource by taking snapshots of the data at a specified interval and threshold.
Hosting integration health checks
Section titled “Hosting integration health checks”The Garnet hosting integration automatically adds a health check for the Garnet resource. The health check verifies that the Garnet instance is running and that a connection can be established to it.