Share via

Unable to connect to the Redis server using Microsoft.AspNetCore.SignalR.StackExchangeRedis with .Net Aspire 13

Hoài Nam Nguyễn 81 Reputation points
2026-03-12T12:11:59+00:00

I'm using .Net Aspire 13, .Net 10. I'm using the library package Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="10.0.3". This is my AppHost:

var cache = builder.AddRedis("cache", 6379);

var presence = builder.AddProject<Projects.Chat_Presense>("chat-presense")    
    .WithReference(cache)
    .WaitFor(cache)
    .WithReference(keycloak)
    .WaitFor(keycloak)
    .WithEndpoint(port: 5001, targetPort: 6001, scheme: "http", name: "chat-presense", isExternal: true);

And in Projects.Chat_Presense, I configured Redis as follows:

builder.Services.AddSignalR().AddStackExchangeRedis("cache");

"ConnectionStrings": {
  "cache": "localhost:6379,password=FxxawDPpD1Tscj9pt2upxH,abortConnect=false"
}

but the error:

Microsoft.AspNetCore.SignalR.StackExchangeRedis.RedisHubLifetimeManager[14]

      Error connecting to Redis.

      StackExchange.Redis.RedisConnectionException: It was not possible to connect to the redis server(s). Error connecting right now. To allow this multiplexer to continue retrying until it's able to connect, use abortConnect=false in your connection string or AbortOnConnectFail=false; in your code.

         at StackExchange.Redis.ConnectionMultiplexer.ConnectImplAsync(ConfigurationOptions configuration, TextWriter writer, Nullable`1 serverType) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 596

         at Microsoft.AspNetCore.SignalR.StackExchangeRedis.RedisOptions.ConnectAsync(TextWriter log)

         at Microsoft.AspNetCore.SignalR.StackExchangeRedis.RedisHubLifetimeManager`1.EnsureRedisServerConnection()

How do I fix this?

Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments

Answer accepted by question author
  1. Danny Nguyen (WICLOUD CORPORATION) 6,700 Reputation points Microsoft External Staff Moderator
    2026-03-13T10:21:47.2733333+00:00

    Hi @Hoài Nam Nguyễn.

    From what I've seen, you’re hitting these problems:

    1. localhost is wrong in Aspire when your app runs in a container.

    localhost:6379 from inside chat-presense points to the chat-presense container, not the Redis container. In Aspire, when you reference Redis with .WithReference(cache), Aspire injects the Redis connection info into the consuming project (including CACHE_HOST, CACHE_PORT, CACHE_URI, etc.). The Aspire Redis integration docs also explicitly show that WithReference(redis) “Provides ConnectionStrings__cache”. (aspire)

    1. AddStackExchangeRedis("cache") does not mean “use the connection string named cache”.

    That overload’s parameter is literally redisConnectionString: String — i.e., it expects the actual Redis connection string, not a key/name to look up in ConnectionStrings. (StackExchangeRedisDependencyInjectionExtensions.AddStackExchangeRedis Method)

    This exact mismatch has been reported as a bug/pitfall with Aspire + SignalR backplane: config.GetConnectionString("redis-cache") has the right value at runtime, but passing the name into AddStackExchangeRedis("redis-cache") fails to connect. (Related issue)

    To fix this, I'd suggest:

    Read the connection string from configuration (which Aspire populates via WithReference(cache)) and pass the resolved value:

    
    var redisCs = builder.Configuration.GetConnectionString("cache");
    
    builder.Services
    
        .AddSignalR()
    
        .AddStackExchangeRedis(redisCs!, options =>
    
        {
    
            // optional: helpful if Redis may start slightly after the app
    
            options.Configuration.AbortOnConnectFail = false;
    
        });
    
    

    And remove (or don’t use for container runs) the hardcoded localhost setting:

    
    "ConnectionStrings": {
    
      "cache": "localhost:6379,..."
    
    }
    
    

    Let Aspire supply the correct Redis endpoint on the Aspire network via WithReference(cache) (ex: using the resource hostname like cache + port, not localhost). Disclaimer: Some links are non-Microsoft website. The pages appear to be providing accurate, safe information. Watch out for ads on the site that may advertise products frequently classifies as a PUP (Potentially Unwanted Products). Thoroughly research any product advertised on the site before you decide to download and install it. 

    If you found my response helpful or informative, I would greatly appreciate it if you could follow this guidance or provide feedback. Thank you.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-03-12T12:12:14.2766667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    AddStackExchangeRedis expects either a full Redis connection string or a ConfigurationOptions object, not just the logical name of the connection string.

    In the code, this line:

    builder.Services.AddSignalR().AddStackExchangeRedis("cache");
    

    passes the literal string "cache" to StackExchange.Redis, so it tries to connect to a server named cache on the default port, which fails.

    Use the actual connection string instead, for example by reading it from configuration:

    var redisConnectionString = builder.Configuration.GetConnectionString("cache");
    
    builder.Services
        .AddSignalR()
        .AddStackExchangeRedis(redisConnectionString);
    

    With the appsettings.json entry:

    "ConnectionStrings": {
      "cache": "localhost:6379,password=FxxawDPpD1Tscj9pt2upxH,abortConnect=false"
    }
    

    Also ensure that the Redis server is actually running and reachable at localhost:6379 from the Chat_Presense project container/process. In containerized Aspire setups, localhost usually refers to the container itself, not the AppHost; use the service host name and port that Aspire assigns (for example, the resource name) in the connection string if needed.


    References:

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.