Share via

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

Hoài Nam Nguyễn 61 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
{count} votes

1 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:

    0 comments No comments

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.