Skip to content
DocsTry Aspire
DocsTry

ValkeyBuilderExtensions Methods

ClassMethods5 members
Provides extension methods for adding Valkey resources to the application model.
AddValkey(IDistributedApplicationBuilder, string, int?)Section titled AddValkey(IDistributedApplicationBuilder, string, int?)extensionIResourceBuilder<ValkeyResource>
Adds a Valkey container to the application model.
public static class ValkeyBuilderExtensions
{
public static IResourceBuilder<ValkeyResource> AddValkey(
this IDistributedApplicationBuilder builder,
string name,
int? port)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.
portint?The host port to bind the underlying container to.
IResourceBuilder<ValkeyResource>A reference to the ApplicationModel.IResourceBuilder`1.
This version of the package defaults to the tag of the container image.
AddValkey(IDistributedApplicationBuilder, string, int?, IResourceBuilder<ParameterResource>)Section titled AddValkey(IDistributedApplicationBuilder, string, int?, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<ValkeyResource>
Adds a Valkey container to the application model.
public static class ValkeyBuilderExtensions
{
public static IResourceBuilder<ValkeyResource> AddValkey(
this IDistributedApplicationBuilder builder,
string name,
int? port = null,
IResourceBuilder<ParameterResource>? password = null)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.
portint?optionalThe host port to bind the underlying container to.
passwordIResourceBuilder<ParameterResource>optionalThe parameter used to provide the password for the Valkey resource. If null a random password will be generated.
IResourceBuilder<ValkeyResource>A reference to the ApplicationModel.IResourceBuilder`1.
This version of the package defaults to the tag of the container image.
WithDataBindMount(IResourceBuilder<ValkeyResource>, string, bool)Section titled WithDataBindMount(IResourceBuilder<ValkeyResource>, string, bool)extensionIResourceBuilder<ValkeyResource>
Adds a bind mount for the data folder to a Valkey container resource and enables Valkey persistence.
public static class ValkeyBuilderExtensions
{
public static IResourceBuilder<ValkeyResource> WithDataBindMount(
this IResourceBuilder<ValkeyResource> builder,
string source,
bool isReadOnly = false)
{
// ...
}
}
builderIResourceBuilder<ValkeyResource>The resource builder.
sourcestringThe source directory on the host to mount into the container.
isReadOnlybooloptional A flag that indicates if this is a read-only mount. Setting this to true will disable Valkey persistence. Defaults to false.
IResourceBuilder<ValkeyResource>The ApplicationModel.IResourceBuilder`1.
Use ValkeyBuilderExtensions.WithPersistence to adjust Valkey persistence configuration, e.g.:
var valkey = builder.AddValkey("valkey")
.WithDataBindMount("mydata")
.WithPersistence(TimeSpan.FromSeconds(10), 5);
WithDataVolume(IResourceBuilder<ValkeyResource>, string?, bool)Section titled WithDataVolume(IResourceBuilder<ValkeyResource>, string?, bool)extensionIResourceBuilder<ValkeyResource>
Adds a named volume for the data folder to a Valkey container resource and enables Valkey persistence.
public static class ValkeyBuilderExtensions
{
public static IResourceBuilder<ValkeyResource> WithDataVolume(
this IResourceBuilder<ValkeyResource> builder,
string? name = null,
bool isReadOnly = false)
{
// ...
}
}
builderIResourceBuilder<ValkeyResource>The resource builder.
namestring?optionalThe name of the volume. Defaults to an auto-generated name based on the application and resource names.
isReadOnlybooloptional A flag that indicates if this is a read-only volume. Setting this to true will disable Valkey persistence. Defaults to false.
IResourceBuilder<ValkeyResource>The ApplicationModel.IResourceBuilder`1.
Use ValkeyBuilderExtensions.WithPersistence to adjust Valkey persistence configuration, e.g.:
var cache = builder.AddValkey("cache")
.WithDataVolume()
.WithPersistence(TimeSpan.FromSeconds(10), 5);
WithPersistence(IResourceBuilder<ValkeyResource>, TimeSpan?, long)Section titled WithPersistence(IResourceBuilder<ValkeyResource>, TimeSpan?, long)extensionIResourceBuilder<ValkeyResource>
Configures a Valkey container resource for persistence.
public static class ValkeyBuilderExtensions
{
public static IResourceBuilder<ValkeyResource> WithPersistence(
this IResourceBuilder<ValkeyResource> builder,
TimeSpan? interval = null,
long keysChangedThreshold = 1)
{
// ...
}
}
builderIResourceBuilder<ValkeyResource>The resource builder.
intervalTimeSpan?optionalThe interval between snapshot exports. Defaults to 60 seconds.
keysChangedThresholdlongoptionalThe number of key change operations required to trigger a snapshot at the interval. Defaults to 1.
IResourceBuilder<ValkeyResource>The ApplicationModel.IResourceBuilder`1.
Use with ValkeyBuilderExtensions.WithDataBindMount or ValkeyBuilderExtensions.WithDataVolume to persist Valkey data across sessions with custom persistence configuration, e.g.:
var cache = builder.AddValkey("cache")
.WithDataVolume()
.WithPersistence(TimeSpan.FromSeconds(10), 5);