Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection failing in startup.cs #12

Closed
ms-mansisinghal opened this issue Jul 24, 2023 · 7 comments
Closed

Connection failing in startup.cs #12

ms-mansisinghal opened this issue Jul 24, 2023 · 7 comments

Comments

@ms-mansisinghal
Copy link

ms-mansisinghal commented Jul 24, 2023

Hi,

I am trying the following code in my startup.cs to make the connection for redis cache but it isn't working for me.


            services.AddStackExchangeRedisCache(async options =>
            {
             
                 var configurationOptions = await ConfigurationOptions.Parse($"{CacheName}:6380").ConfigureForAzureWithSystemAssignedManagedIdentityAsync(principalID);
                 options.ConfigurationOptions = configurationOptions;
                 var connectionMultiplexer = ConnectionMultiplexer.ConnectAsync(configurationOptions);
                
                options.InstanceName = Constants.UserManagementService;

            });

Can someone provide a sample for this or managed identity in startup.cs

@sachinsaner
Copy link

Have you seen the sample code in this Repo for connecting with Service principal? What error you are getting? https://github.com/Azure/Microsoft.Azure.StackExchangeRedis/blob/main/sample/Sample.cs#L66

@lsannicolas
Copy link
Collaborator

Hello, could you update with the error and where you're running the startup.cs? Connecting with AAD is only supported on Azure VMs for now.

@ms-mansisinghal
Copy link
Author

ms-mansisinghal commented Jul 25, 2023

Hey, we are trying to connect our Reddis cache to an Azure App service. Is that possible?
Our goal is to switch to managed identity so we followed the steps on this link
And I am not able to see the error in the logs but the API calls based on this redis are failing.
I have updated the managed Identity code. Tried this and Service principal as well.

@sven5
Copy link

sven5 commented Sep 20, 2023

It seems this library does not work together with ASP.NET Core's Microsoft.Extensions.Caching.StackExchangeRedis extensions. Is there anything in progress to get this working?
@eerhardt @philon-msft

Please show a sample using ASP.NET Core Web App.

@eerhardt
Copy link
Member

eerhardt commented Sep 20, 2023

cc @mgravell @sebastienros

@philon-msft
Copy link
Contributor

The extension built out of this repo is only for the StackExchange.Redis library itself. To request AAD support for Microsoft.Extensions.Caching.StackExchangeRedis, I'd recommend creating an issue in the https://github.com/dotnet/aspnetcore repo.

@RichFinn-WTW
Copy link

RichFinn-WTW commented Aug 6, 2024

It seems this library does not work together with ASP.NET Core's Microsoft.Extensions.Caching.StackExchangeRedis extensions. Is there anything in progress to get this working? @eerhardt @philon-msft

Please show a sample using ASP.NET Core Web App.

@sven5 - we were able to get Microsoft.Azure.StackExchangeRedis working with Microsoft.Extensions.Caching.StackExchangeRedis, adding Entra auth to our Redis resources via an extension method and still using IDistributedCache

csproj:

<PackageReference Include="Microsoft.Azure.StackExchangeRedis" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.7" />

Extension method:


public static class CachingExtensions
{
    public static async Task<IServiceCollection> AddCaching(this IServiceCollection services, IConfiguration configuration)
    {
        services.Configure<CachingOptions>(configuration.GetSection(CachingOptions.Position));
        var settings = configuration.GetSection(CachingOptions.Position).Get<CachingOptions>(); 
        
        var configurationOptions = ConfigurationOptions.Parse(settings.RedisConnectionString);
        await configurationOptions.ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential());
        configurationOptions.DefaultDatabase = settings.RedisDefaultDatabase;
        
        services.AddStackExchangeRedisCache(options =>
        {
            options.ConfigurationOptions = configurationOptions;
        });       

        return services;
    }
}

Program.cs (minimal):

var builder = WebApplication.CreateBuilder(args);

await builder.Services.AddCaching(builder.Configuration);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants