RedisBuilderExtensions Methods
AddRedis(IDistributedApplicationBuilder, string, int?) Section titled AddRedis(IDistributedApplicationBuilder, string, int?)extensionIResourceBuilder<RedisResource> public static class RedisBuilderExtensions{ public static IResourceBuilder<RedisResource> AddRedis( this IDistributedApplicationBuilder builder, string name, int? port) { // ... }}Parameters
builderIDistributedApplicationBuilder The 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.Returns
IResourceBuilder<RedisResource> A reference to the ApplicationModel.IResourceBuilder`1 .Remarks
This resource includes built-in health checks. When this resource is referenced as a dependency using the Resource extension method then the dependent resource will wait until the Redis resource is able to service requests.
AddRedis(IDistributedApplicationBuilder, string, int?, IResourceBuilder<ParameterResource>) Section titled AddRedis(IDistributedApplicationBuilder, string, int?, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<RedisResource> public static class RedisBuilderExtensions{ public static IResourceBuilder<RedisResource> AddRedis( this IDistributedApplicationBuilder builder, string name, int? port = null, IResourceBuilder<ParameterResource>? password = null) { // ... }}Parameters
builderIDistributedApplicationBuilder The 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.Returns
IResourceBuilder<RedisResource> A reference to the ApplicationModel.IResourceBuilder`1 .Remarks
This resource includes built-in health checks. When this resource is referenced as a dependency using the Resource extension method then the dependent resource will wait until the Redis resource is able to service requests.
WithDataBindMount(IResourceBuilder<RedisResource>, string, bool) Section titled WithDataBindMount(IResourceBuilder<RedisResource>, string, bool)extensionIResourceBuilder<RedisResource> public static class RedisBuilderExtensions{ public static IResourceBuilder<RedisResource> WithDataBindMount( this IResourceBuilder<RedisResource> builder, string source, bool isReadOnly = false) { // ... }}Parameters
builderIResourceBuilder<RedisResource> The resource builder.sourcestringThe source directory on the host to mount into the container.isReadOnly booloptional A flag that indicates if this is a read-only mount. Setting this to true will disable Redis persistence. Defaults to false. Returns
IResourceBuilder<RedisResource> The ApplicationModel.IResourceBuilder`1 .Remarks
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> public static class RedisBuilderExtensions{ public static IResourceBuilder<RedisInsightResource> WithDataBindMount( this IResourceBuilder<RedisInsightResource> builder, string source) { // ... }}Parameters
builderIResourceBuilder<RedisInsightResource> The resource builder.sourcestringThe source directory on the host to mount into the container.Returns
IResourceBuilder<RedisInsightResource> The ApplicationModel.IResourceBuilder`1 .WithDataVolume(IResourceBuilder<RedisResource>, string?, bool) Section titled WithDataVolume(IResourceBuilder<RedisResource>, string?, bool)extensionIResourceBuilder<RedisResource> public static class RedisBuilderExtensions{ public static IResourceBuilder<RedisResource> WithDataVolume( this IResourceBuilder<RedisResource> builder, string? name = null, bool isReadOnly = false) { // ... }}Parameters
builderIResourceBuilder<RedisResource> The resource builder.namestring?optionalThe name of the volume. Defaults to an auto-generated name based on the application and resource names.isReadOnly booloptional A flag that indicates if this is a read-only volume. Setting this to true will disable Redis persistence. Defaults to false. Returns
IResourceBuilder<RedisResource> The ApplicationModel.IResourceBuilder`1 .Remarks
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> public static class RedisBuilderExtensions{ public static IResourceBuilder<RedisInsightResource> WithDataVolume( this IResourceBuilder<RedisInsightResource> builder, string? name = null) { // ... }}Parameters
builderIResourceBuilder<RedisInsightResource> The resource builder.namestring?optionalThe name of the volume. Defaults to an auto-generated name based on the application and resource names.Returns
IResourceBuilder<RedisInsightResource> The ApplicationModel.IResourceBuilder`1 .WithHostPort(IResourceBuilder<RedisCommanderResource>, int?) Section titled WithHostPort(IResourceBuilder<RedisCommanderResource>, int?)extensionIResourceBuilder<RedisCommanderResource> public static class RedisBuilderExtensions{ public static IResourceBuilder<RedisCommanderResource> WithHostPort( this IResourceBuilder<RedisCommanderResource> builder, int? port) { // ... }}Parameters
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.Returns
IResourceBuilder<RedisCommanderResource> The resource builder for RedisCommander.WithHostPort(IResourceBuilder<RedisInsightResource>, int?) Section titled WithHostPort(IResourceBuilder<RedisInsightResource>, int?)extensionIResourceBuilder<RedisInsightResource> public static class RedisBuilderExtensions{ public static IResourceBuilder<RedisInsightResource> WithHostPort( this IResourceBuilder<RedisInsightResource> builder, int? port) { // ... }}Parameters
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.Returns
IResourceBuilder<RedisInsightResource> The resource builder for RedisInsight.WithHostPort(IResourceBuilder<RedisResource>, int?) Section titled WithHostPort(IResourceBuilder<RedisResource>, int?)extensionIResourceBuilder<RedisResource> public static class RedisBuilderExtensions{ public static IResourceBuilder<RedisResource> WithHostPort( this IResourceBuilder<RedisResource> builder, int? port) { // ... }}Parameters
builderIResourceBuilder<RedisResource> The resource builder.portint?The port to bind on the host. If null is used random port will be assigned.Returns
IResourceBuilder<RedisResource> The ApplicationModel.IResourceBuilder`1 .WithModule(IResourceBuilder<RedisResource>, string) Section titled WithModule(IResourceBuilder<RedisResource>, string)extensionIResourceBuilder<RedisResource> public static class RedisBuilderExtensions{ public static IResourceBuilder<RedisResource> WithModule( this IResourceBuilder<RedisResource> builder, string path) { // ... }}Parameters
builderIResourceBuilder<RedisResource> The resource builder.pathstringThe absolute path to the Redis module inside the Redis container.Returns
IResourceBuilder<RedisResource> The ApplicationModel.IResourceBuilder`1 .Remarks
redis-server as a --loadmodule argument. Redis resolves the path inside the container, not on the host. To load a module built on the host machine, mount it into the Redis container first and then use the mounted container path. Use RedisModules for well-known module paths that are included in the default Redis container image. var cache = builder.AddRedis("cache") .WithModule(RedisModules.Json) .WithModule(RedisModules.Search);
var customModuleCache = builder.AddRedis("custom-cache") .WithBindMount( "/host/redis/modules", "/redis/modules", isReadOnly: true) .WithModule("/redis/modules/custom-module.so");WithPassword(IResourceBuilder<RedisResource>, IResourceBuilder<ParameterResource>) Section titled WithPassword(IResourceBuilder<RedisResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<RedisResource> public static class RedisBuilderExtensions{ public static IResourceBuilder<RedisResource> WithPassword( this IResourceBuilder<RedisResource> builder, IResourceBuilder<ParameterResource>? password) { // ... }}Parameters
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.Returns
IResourceBuilder<RedisResource> The ApplicationModel.IResourceBuilder`1 .WithPersistence(IResourceBuilder<RedisResource>, TimeSpan?, long) Section titled WithPersistence(IResourceBuilder<RedisResource>, TimeSpan?, long)extensionIResourceBuilder<RedisResource> public static class RedisBuilderExtensions{ public static IResourceBuilder<RedisResource> WithPersistence( this IResourceBuilder<RedisResource> builder, TimeSpan? interval = null, long keysChangedThreshold = 1) { // ... }}Parameters
builderIResourceBuilder<RedisResource> The resource builder.intervalTimeSpan? optionalThe interval between snapshot exports. Defaults to 60 seconds.keysChangedThreshold longoptionalThe number of key change operations required to trigger a snapshot at the interval. Defaults to 1.Returns
IResourceBuilder<RedisResource> The ApplicationModel.IResourceBuilder`1 .Remarks
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> 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) { // ... }}Parameters
builderIResourceBuilder<RedisResource> The ApplicationModel.IResourceBuilder`1 for the RedisResource .configureContainer Action<IResourceBuilder<RedisCommanderResource>> optionalConfiguration callback for Redis Commander container resource.containerName string?optionalOverride the container name used for Redis Commander.Remarks
WithRedisInsight(IResourceBuilder<RedisResource>, Action<IResourceBuilder<RedisInsightResource>>, string?) Section titled WithRedisInsight(IResourceBuilder<RedisResource>, Action<IResourceBuilder<RedisInsightResource>>, string?)extensionIResourceBuilder<RedisResource> 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) { // ... }}Parameters
builderIResourceBuilder<RedisResource> The ApplicationModel.IResourceBuilder`1 for the RedisResource .configureContainer Action<IResourceBuilder<RedisInsightResource>> optionalConfiguration callback for Redis Insight container resource.containerName string?optionalOverride the container name used for Redis Insight.Remarks
WithRepl(IResourceBuilder<RedisResource>) Section titled WithRepl(IResourceBuilder<RedisResource>)extensionIResourceBuilder<RedisResource> public static class RedisBuilderExtensions{ public static IResourceBuilder<RedisResource> WithRepl( this IResourceBuilder<RedisResource> builder) { // ... }}Parameters
builderIResourceBuilder<RedisResource> The Redis resource builder.Returns
IResourceBuilder<RedisResource> The resource builder for chaining.Exceptions
ArgumentNullExceptionbuilder is null.Remarks
Examples
builder.AddRedis("redis").WithRepl();