Valkey hosting integration
Este conteúdo não está disponível em sua língua ainda.
The Valkey hosting integration models a Valkey resource as the ValkeyResource type. To access this type and APIs, add the 📦 Aspire.Hosting.Valkey NuGet package in your AppHost project:
aspire add valkeyA Aspire CLI é interativa; escolha o resultado adequado quando solicitado:
Select an integration to add:
> valkey (Aspire.Hosting.Valkey)> Other results listed as selectable options...#:package Aspire.Hosting.Valkey@*<PackageReference Include="Aspire.Hosting.Valkey" Version="*" />Add Valkey resource
Section titled “Add Valkey resource”In your AppHost project, call AddValkey on the builder instance to add a Valkey resource:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddValkey("cache");
var myService = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);When Aspire adds a container image to the AppHost, it creates a new Valkey instance on your local machine.
Add Valkey resource with data volume
Section titled “Add Valkey resource with data volume”To add a data volume to the Valkey resource, call the WithDataVolume method:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddValkey("cache") .WithDataVolume(isReadOnly: false);
var myService = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);The data volume is used to persist the Valkey data outside the lifecycle of its container. The data volume is mounted at the /data path in the Valkey container.
Add Valkey resource with data bind mount
Section titled “Add Valkey resource with data bind mount”To add a data bind mount to the Valkey resource, call the WithDataBindMount method:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddValkey("cache") .WithDataBindMount( source: @"C:\Valkey\Data", isReadOnly: false);
var myService = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);Add Valkey resource with persistence
Section titled “Add Valkey resource with persistence”To add persistence to the Valkey resource, call the WithPersistence method with either the data volume or data bind mount:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddValkey("cache") .WithDataVolume() .WithPersistence( interval: TimeSpan.FromMinutes(5), keysChangedThreshold: 100);
var myService = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);The preceding code adds persistence to the Valkey resource by taking snapshots of the data at a specified interval and threshold.
Hosting integration health checks
Section titled “Hosting integration health checks”The Valkey hosting integration automatically adds a health check for the Valkey resource. The health check verifies that the Valkey instance is running and that a connection can be established to it.