Redis Distributed Caching hosting integration
このコンテンツはまだ日本語訳がありません。
The Redis® hosting integration models a Redis resource as the RedisResource type. To access this type and APIs, add the 📦 Aspire.Hosting.Redis NuGet package in your AppHost project:
aspire add redisAspire CLI は対話的です。求められたら適切な結果を選択してください:
Select an integration to add:
> redis (Aspire.Hosting.Redis)> Other results listed as selectable options...#:package Aspire.Hosting.Redis@*<PackageReference Include="Aspire.Hosting.Redis" Version="*" />Add Redis resource
Section titled “Add Redis resource”In your AppHost project, call AddRedis on the builder instance to add a Redis resource:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache");
var myService = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);When Aspire adds a container image to the AppHost, it creates a new Redis instance on your local machine.
Add Redis resource with data volume
Section titled “Add Redis resource with data volume”To add a data volume to the Redis resource, call the WithDataVolume method:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache") .WithDataVolume(isReadOnly: false);
var myService = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);The data volume is used to persist the Redis data outside the lifecycle of its container. The data volume is mounted at the /data path in the Redis container.
Add Redis resource with persistence
Section titled “Add Redis resource with persistence”To add persistence to the Redis resource, call the WithPersistence method with either the data volume or data bind mount:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache") .WithDataVolume() .WithPersistence( interval: TimeSpan.FromMinutes(5), keysChangedThreshold: 100);
var myService = builder.AddProject<Projects.ExampleProject>() .WithReference(cache);The preceding code adds persistence to the Redis resource by taking snapshots of the Redis data at a specified interval and threshold.
For more Redis hosting integration options, see the main Redis hosting integration page.