Skip to content
DocsTry Aspire
DocsTry

RedisBuilderExtensions Methods

ClassMethods13 members
Provides extension methods for adding Redis resources to the application model.
AddRedis(IDistributedApplicationBuilder, string, int?)Section titled AddRedis(IDistributedApplicationBuilder, string, int?)extensionIResourceBuilder<RedisResource>
Adds a Redis container to the application model.
public static class RedisBuilderExtensions
{
public static IResourceBuilder<RedisResource> AddRedis(
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<RedisResource>A reference to the ApplicationModel.IResourceBuilder`1.

This resource includes built-in health checks. When this resource is referenced as a dependency using the ResourceBuilderExtensions.WaitFor extension method then the dependent resource will wait until the Redis resource is able to service requests.

This version of the package defaults to the tag of the container image.
AddRedis(IDistributedApplicationBuilder, string, int?, IResourceBuilder<ParameterResource>)Section titled AddRedis(IDistributedApplicationBuilder, string, int?, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<RedisResource>
Adds a Redis container to the application model.
public static class RedisBuilderExtensions
{
public static IResourceBuilder<RedisResource> AddRedis(
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 Redis resource. If null a random password will be generated.
IResourceBuilder<RedisResource>A reference to the ApplicationModel.IResourceBuilder`1.

This resource includes built-in health checks. When this resource is referenced as a dependency using the ResourceBuilderExtensions.WaitFor extension method then the dependent resource will wait until the Redis resource is able to service requests.

This version of the package defaults to the tag of the container image.
WithDataBindMount(IResourceBuilder<RedisResource>, string, bool)Section titled WithDataBindMount(IResourceBuilder<RedisResource>, string, bool)extensionIResourceBuilder<RedisResource>
Adds a bind mount for the data folder to a Redis container resource and enables Redis persistence.
public static class RedisBuilderExtensions
{
public static IResourceBuilder<RedisResource> WithDataBindMount(
this IResourceBuilder<RedisResource> builder,
string source,
bool isReadOnly = false)
{
// ...
}
}
builderIResourceBuilder<RedisResource>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 Redis persistence. Defaults to false.
IResourceBuilder<RedisResource>The ApplicationModel.IResourceBuilder`1.
Use RedisBuilderExtensions.WithPersistence to adjust Redis persistence configuration, e.g.:
var cache = builder.AddRedis("cache")
.WithDataBindMount("myredisdata")
.WithPersistence(TimeSpan.FromSeconds(10), 5);
WithDataBindMount(IResourceBuilder<RedisInsightResource>, string)Section titled WithDataBindMount(IResourceBuilder<RedisInsightResource>, string)extensionIResourceBuilder<RedisInsightResource>
Adds a bind mount for the data folder to a Redis Insight container resource.
public static class RedisBuilderExtensions
{
public static IResourceBuilder<RedisInsightResource> WithDataBindMount(
this IResourceBuilder<RedisInsightResource> builder,
string source)
{
// ...
}
}
builderIResourceBuilder<RedisInsightResource>The resource builder.
sourcestringThe source directory on the host to mount into the container.
IResourceBuilder<RedisInsightResource>The ApplicationModel.IResourceBuilder`1.
WithDataVolume(IResourceBuilder<RedisResource>, string?, bool)Section titled WithDataVolume(IResourceBuilder<RedisResource>, string?, bool)extensionIResourceBuilder<RedisResource>
Adds a named volume for the data folder to a Redis container resource and enables Redis persistence.
public static class RedisBuilderExtensions
{
public static IResourceBuilder<RedisResource> WithDataVolume(
this IResourceBuilder<RedisResource> builder,
string? name = null,
bool isReadOnly = false)
{
// ...
}
}
builderIResourceBuilder<RedisResource>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 Redis persistence. Defaults to false.
IResourceBuilder<RedisResource>The ApplicationModel.IResourceBuilder`1.
Use RedisBuilderExtensions.WithPersistence to adjust Redis persistence configuration, e.g.:
var cache = builder.AddRedis("cache")
.WithDataVolume()
.WithPersistence(TimeSpan.FromSeconds(10), 5);
WithDataVolume(IResourceBuilder<RedisInsightResource>, string?)Section titled WithDataVolume(IResourceBuilder<RedisInsightResource>, string?)extensionIResourceBuilder<RedisInsightResource>
Adds a named volume for the data folder to a Redis Insight container resource.
public static class RedisBuilderExtensions
{
public static IResourceBuilder<RedisInsightResource> WithDataVolume(
this IResourceBuilder<RedisInsightResource> builder,
string? name = null)
{
// ...
}
}
builderIResourceBuilder<RedisInsightResource>The resource builder.
namestring?optionalThe name of the volume. Defaults to an auto-generated name based on the application and resource names.
IResourceBuilder<RedisInsightResource>The ApplicationModel.IResourceBuilder`1.
WithHostPort(IResourceBuilder<RedisCommanderResource>, int?)Section titled WithHostPort(IResourceBuilder<RedisCommanderResource>, int?)extensionIResourceBuilder<RedisCommanderResource>
Configures the host port that the Redis Commander resource is exposed on instead of using randomly assigned port.
public static class RedisBuilderExtensions
{
public static IResourceBuilder<RedisCommanderResource> WithHostPort(
this IResourceBuilder<RedisCommanderResource> builder,
int? port)
{
// ...
}
}
builderIResourceBuilder<RedisCommanderResource>The resource builder for Redis Commander.
portint?The port to bind on the host. If null is used random port will be assigned.
IResourceBuilder<RedisCommanderResource>The resource builder for RedisCommander.
WithHostPort(IResourceBuilder<RedisInsightResource>, int?)Section titled WithHostPort(IResourceBuilder<RedisInsightResource>, int?)extensionIResourceBuilder<RedisInsightResource>
Configures the host port that the Redis Insight resource is exposed on instead of using randomly assigned port.
public static class RedisBuilderExtensions
{
public static IResourceBuilder<RedisInsightResource> WithHostPort(
this IResourceBuilder<RedisInsightResource> builder,
int? port)
{
// ...
}
}
builderIResourceBuilder<RedisInsightResource>The resource builder for Redis Insight.
portint?The port to bind on the host. If null is used random port will be assigned.
IResourceBuilder<RedisInsightResource>The resource builder for RedisInsight.
WithHostPort(IResourceBuilder<RedisResource>, int?)Section titled WithHostPort(IResourceBuilder<RedisResource>, int?)extensionIResourceBuilder<RedisResource>
Configures the host port that the Redis resource is exposed on instead of using randomly assigned port.
public static class RedisBuilderExtensions
{
public static IResourceBuilder<RedisResource> WithHostPort(
this IResourceBuilder<RedisResource> builder,
int? port)
{
// ...
}
}
builderIResourceBuilder<RedisResource>The resource builder.
portint?The port to bind on the host. If null is used random port will be assigned.
IResourceBuilder<RedisResource>The ApplicationModel.IResourceBuilder`1.
WithPassword(IResourceBuilder<RedisResource>, IResourceBuilder<ParameterResource>)Section titled WithPassword(IResourceBuilder<RedisResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<RedisResource>
Configures the password that the Redis resource is used.
public static class RedisBuilderExtensions
{
public static IResourceBuilder<RedisResource> WithPassword(
this IResourceBuilder<RedisResource> builder,
IResourceBuilder<ParameterResource>? password)
{
// ...
}
}
builderIResourceBuilder<RedisResource>The resource builder.
passwordIResourceBuilder<ParameterResource>The parameter used to provide the password for the Redis resource. If null, no password will be configured.
IResourceBuilder<RedisResource>The ApplicationModel.IResourceBuilder`1.
WithPersistence(IResourceBuilder<RedisResource>, TimeSpan?, long)Section titled WithPersistence(IResourceBuilder<RedisResource>, TimeSpan?, long)extensionIResourceBuilder<RedisResource>
Configures a Redis container resource for persistence.
public static class RedisBuilderExtensions
{
public static IResourceBuilder<RedisResource> WithPersistence(
this IResourceBuilder<RedisResource> builder,
TimeSpan? interval = null,
long keysChangedThreshold = 1)
{
// ...
}
}
builderIResourceBuilder<RedisResource>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<RedisResource>The ApplicationModel.IResourceBuilder`1.
Use with RedisBuilderExtensions.WithDataBindMount or RedisBuilderExtensions.WithDataVolume to persist Redis data across sessions with custom persistence configuration, e.g.:
var cache = builder.AddRedis("cache")
.WithDataVolume()
.WithPersistence(TimeSpan.FromSeconds(10), 5);
WithRedisCommander(IResourceBuilder<RedisResource>, Action<IResourceBuilder<RedisCommanderResource>>, string?)Section titled WithRedisCommander(IResourceBuilder<RedisResource>, Action<IResourceBuilder<RedisCommanderResource>>, string?)extensionIResourceBuilder<RedisResource>
Configures a container resource for Redis Commander which is pre-configured to connect to the RedisResource that this method is used on.
public static class RedisBuilderExtensions
{
public static IResourceBuilder<RedisResource> WithRedisCommander(
this IResourceBuilder<RedisResource> builder,
Action<IResourceBuilder<RedisCommanderResource>>? configureContainer = null,
string? containerName = null)
{
// ...
}
}
builderIResourceBuilder<RedisResource>The ApplicationModel.IResourceBuilder`1 for the RedisResource.
configureContainerAction<IResourceBuilder<RedisCommanderResource>>optionalConfiguration callback for Redis Commander container resource.
containerNamestring?optionalOverride the container name used for Redis Commander.
This version of the package defaults to the tag of the container image.
WithRedisInsight(IResourceBuilder<RedisResource>, Action<IResourceBuilder<RedisInsightResource>>, string?)Section titled WithRedisInsight(IResourceBuilder<RedisResource>, Action<IResourceBuilder<RedisInsightResource>>, string?)extensionIResourceBuilder<RedisResource>
Configures a container resource for Redis Insight which is pre-configured to connect to the RedisResource that this method is used on.
public static class RedisBuilderExtensions
{
public static IResourceBuilder<RedisResource> WithRedisInsight(
this IResourceBuilder<RedisResource> builder,
Action<IResourceBuilder<RedisInsightResource>>? configureContainer = null,
string? containerName = null)
{
// ...
}
}
builderIResourceBuilder<RedisResource>The ApplicationModel.IResourceBuilder`1 for the RedisResource.
configureContainerAction<IResourceBuilder<RedisInsightResource>>optionalConfiguration callback for Redis Insight container resource.
containerNamestring?optionalOverride the container name used for Redis Insight.
This version of the package defaults to the tag of the container image.