ValkeyBuilderExtensions.WithPersistence Method

Definition

Configures a Valkey container resource for persistence.

C#
public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ValkeyResource> WithPersistence(this Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ValkeyResource> builder, TimeSpan? interval = default, long keysChangedThreshold = 1);

Parameters

builder
IResourceBuilder<ValkeyResource>

The resource builder.

interval
Nullable<TimeSpan>

The interval between snapshot exports. Defaults to 60 seconds.

keysChangedThreshold
Int64

The number of key change operations required to trigger a snapshot at the interval. Defaults to 1.

Returns

The IResourceBuilder<T>.

Examples

Use with WithDataBindMount(IResourceBuilder<ValkeyResource>, String, Boolean) or WithDataVolume(IResourceBuilder<ValkeyResource>, String, Boolean) to persist Valkey data across sessions with custom persistence configuration, e.g.:

C#
var cache = builder.AddValkey("cache")
                   .WithDataVolume()
                   .WithPersistence(TimeSpan.FromSeconds(10), 5);

Remarks

Use with WithDataBindMount(IResourceBuilder<ValkeyResource>, String, Boolean) or WithDataVolume(IResourceBuilder<ValkeyResource>, String, Boolean) to persist Valkey data across sessions with custom persistence configuration, e.g.:
C#
var cache = builder.AddValkey("cache")
                   .WithDataVolume()
                   .WithPersistence(TimeSpan.FromSeconds(10), 5);

Applies to

Продукт Версии
.NET Aspire 8.0.0, 9.0.0, 9.1.0