# AspireRedisExtensions Methods

- Package: [Aspire.StackExchange.Redis](/reference/api/csharp/aspire.stackexchange.redis.md)
- Type: [AspireRedisExtensions](/reference/api/csharp/aspire.stackexchange.redis/aspireredisextensions.md)
- Kind: `Methods`
- Members: `4`

Provides extension methods for registering Redis-related services in an `Hosting.IHostApplicationBuilder`.

## AddKeyedRedisClient(IHostApplicationBuilder, string, Action<StackExchangeRedisSettings>, Action<ConfigurationOptions>)

- Name: `AddKeyedRedisClient(IHostApplicationBuilder, string, Action<StackExchangeRedisSettings>, Action<ConfigurationOptions>)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Components/Aspire.StackExchange.Redis/AspireRedisExtensions.cs#L71)

Registers `Redis.IConnectionMultiplexer` as a keyed singleton for the given `name` in the services provided by the `builder`. Enables retries, corresponding health check, logging, and telemetry.

```csharp
public static class AspireRedisExtensions
{
    public static void AddKeyedRedisClient(
        this IHostApplicationBuilder builder,
        string name,
        Action<StackExchangeRedisSettings>? configureSettings = null,
        Action<ConfigurationOptions>? configureOptions = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `name` (`string`)
  The name of the component, which is used as the `ServiceDescriptor.ServiceKey` of the service and also to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<StackExchangeRedisSettings>`) `optional`
  An optional method that can be used for customizing the [StackExchangeRedisSettings](/reference/api/csharp/aspire.stackexchange.redis/stackexchangeredissettings.md). It's invoked after the settings are read from the configuration.
- `configureOptions` (`Action<ConfigurationOptions>`) `optional`
  An optional method that can be used for customizing the `Redis.ConfigurationOptions`. It's invoked after the options are read from the configuration.

## Remarks

Reads the configuration from "Aspire:StackExchange:Redis:{name}" section.

## AddKeyedRedisClientBuilder(IHostApplicationBuilder, string, Action<StackExchangeRedisSettings>, Action<ConfigurationOptions>)

- Name: `AddKeyedRedisClientBuilder(IHostApplicationBuilder, string, Action<StackExchangeRedisSettings>, Action<ConfigurationOptions>)`
- Modifiers: `extension`
- Returns: [AspireRedisClientBuilder](/reference/api/csharp/aspire.stackexchange.redis/aspireredisclientbuilder.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Components/Aspire.StackExchange.Redis/AspireRedisExtensions.cs#L88-L90)

Registers `Redis.IConnectionMultiplexer` as a keyed singleton for the given `name` in the services provided by the `builder`. Enables retries, corresponding health check, logging, and telemetry.

```csharp
public static class AspireRedisExtensions
{
    public static AspireRedisClientBuilder AddKeyedRedisClientBuilder(
        this IHostApplicationBuilder builder,
        string name,
        Action<StackExchangeRedisSettings>? configureSettings = null,
        Action<ConfigurationOptions>? configureOptions = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `name` (`string`)
  The name of the component, which is used as the `ServiceDescriptor.ServiceKey` of the service and also to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<StackExchangeRedisSettings>`) `optional`
  An optional method that can be used for customizing the [StackExchangeRedisSettings](/reference/api/csharp/aspire.stackexchange.redis/stackexchangeredissettings.md). It's invoked after the settings are read from the configuration.
- `configureOptions` (`Action<ConfigurationOptions>`) `optional`
  An optional method that can be used for customizing the `Redis.ConfigurationOptions`. It's invoked after the options are read from the configuration.

## Remarks

Reads the configuration from "Aspire:StackExchange:Redis:{name}" section.

## AddRedisClient(IHostApplicationBuilder, string, Action<StackExchangeRedisSettings>, Action<ConfigurationOptions>)

- Name: `AddRedisClient(IHostApplicationBuilder, string, Action<StackExchangeRedisSettings>, Action<ConfigurationOptions>)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Components/Aspire.StackExchange.Redis/AspireRedisExtensions.cs#L39)

Registers `Redis.IConnectionMultiplexer` as a singleton in the services provided by the `builder`. Enables retries, corresponding health check, logging, and telemetry.

```csharp
public static class AspireRedisExtensions
{
    public static void AddRedisClient(
        this IHostApplicationBuilder builder,
        string connectionName,
        Action<StackExchangeRedisSettings>? configureSettings = null,
        Action<ConfigurationOptions>? configureOptions = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `connectionName` (`string`)
  A name used to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<StackExchangeRedisSettings>`) `optional`
  An optional method that can be used for customizing the [StackExchangeRedisSettings](/reference/api/csharp/aspire.stackexchange.redis/stackexchangeredissettings.md). It's invoked after the settings are read from the configuration.
- `configureOptions` (`Action<ConfigurationOptions>`) `optional`
  An optional method that can be used for customizing the `Redis.ConfigurationOptions`. It's invoked after the options are read from the configuration.

## Remarks

Reads the configuration from "Aspire:StackExchange:Redis" section.

## AddRedisClientBuilder(IHostApplicationBuilder, string, Action<StackExchangeRedisSettings>, Action<ConfigurationOptions>)

- Name: `AddRedisClientBuilder(IHostApplicationBuilder, string, Action<StackExchangeRedisSettings>, Action<ConfigurationOptions>)`
- Modifiers: `extension`
- Returns: [AspireRedisClientBuilder](/reference/api/csharp/aspire.stackexchange.redis/aspireredisclientbuilder.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Components/Aspire.StackExchange.Redis/AspireRedisExtensions.cs#L55)

Registers `Redis.IConnectionMultiplexer` as a singleton in the services provided by the `builder`. Enables retries, corresponding health check, logging, and telemetry.

```csharp
public static class AspireRedisExtensions
{
    public static AspireRedisClientBuilder AddRedisClientBuilder(
        this IHostApplicationBuilder builder,
        string connectionName,
        Action<StackExchangeRedisSettings>? configureSettings = null,
        Action<ConfigurationOptions>? configureOptions = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `connectionName` (`string`)
  A name used to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<StackExchangeRedisSettings>`) `optional`
  An optional method that can be used for customizing the [StackExchangeRedisSettings](/reference/api/csharp/aspire.stackexchange.redis/stackexchangeredissettings.md). It's invoked after the settings are read from the configuration.
- `configureOptions` (`Action<ConfigurationOptions>`) `optional`
  An optional method that can be used for customizing the `Redis.ConfigurationOptions`. It's invoked after the options are read from the configuration.

## Remarks

Reads the configuration from "Aspire:StackExchange:Redis" section.
