Skip to content
Docs Try Aspire

ValkeyBuilderExtensions Methods

Class Methods 5 members
Provides extension methods for adding Valkey resources to the application model.
AddValkey(IDistributedApplicationBuilder, string, int?) Section titled AddValkey(IDistributedApplicationBuilder, string, int?) extension IResourceBuilder<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)
{
// ...
}
}
builder IDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder.
name string The name of the resource. This name will be used as the connection string name when referenced in a dependency.
port int? 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>) extension IResourceBuilder<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)
{
// ...
}
}
builder IDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder.
name string The name of the resource. This name will be used as the connection string name when referenced in a dependency.
port int? optional The host port to bind the underlying container to.
password IResourceBuilder<ParameterResource> optional The 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) extension IResourceBuilder<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)
{
// ...
}
}
builder IResourceBuilder<ValkeyResource> The resource builder.
source string The source directory on the host to mount into the container.
isReadOnly bool optional 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) extension IResourceBuilder<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)
{
// ...
}
}
builder IResourceBuilder<ValkeyResource> The resource builder.
name string? optional The name of the volume. Defaults to an auto-generated name based on the application and resource names.
isReadOnly bool optional 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) extension IResourceBuilder<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)
{
// ...
}
}
builder IResourceBuilder<ValkeyResource> The resource builder.
interval TimeSpan? optional The interval between snapshot exports. Defaults to 60 seconds.
keysChangedThreshold long optional The 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);