RedisBuilderExtensions.WithPersistence Method

Definition

Configures a Redis container resource for persistence.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.RedisResource> WithPersistence (this Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.RedisResource> builder, TimeSpan? interval = default, long keysChangedThreshold = 1);
static member WithPersistence : Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.RedisResource> * Nullable<TimeSpan> * int64 -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.RedisResource>
<Extension()>
Public Function WithPersistence (builder As IResourceBuilder(Of RedisResource), Optional interval As Nullable(Of TimeSpan) = Nothing, Optional keysChangedThreshold As Long = 1) As IResourceBuilder(Of RedisResource)

Parameters

builder
IResourceBuilder<RedisResource>

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>.

Remarks

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

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

Applies to