ConnectionMultiplexer exception caused when trying to invoke webAPI endpoints –

I am facing an exception(ConnectionMultiplexer) message when trying to access a .NetCore 8 webAPI endpoint. I tried to use repositoryPattern in my project so there’s a GenericRepository interface. I registered my dependencies in a separate class and then added it to my Program.cs class using Services.Add().Let me post the relevant pieces of code so that the structure is understandable to you. There’s a whole lot of inter-related code so pls bear with me and pardon me if it appears too verbose.

**** I have removed the unrelated code and edited my question for the sake of brevity and clarity.

The StackExchange.Redis exception I am getting is

HirectStore.API.Infrastructure.Services.ResponseCacheService.GetCachedResponseAsync(String
cacheKey) in D:Code
StackProjectsHirectStoreHirectStoreBackendHirectStore.APIInfrastructureServicesResponseCacheService.cs:line
35rn

In my Program.cs –

builder.Services.AddSingleton<IConnectionMultiplexer>(c =>
{
    var multiplexerconfig = ConfigurationOptions.Parse("localhost, abortConnect=false");
    return ConnectionMultiplexer.Connect(multiplexerconfig);

});
builder.Services.AddApplicationServices();

I inspected the exception in my ExceptionMiddleware class and it says the following –

‘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.’

This is how I registered the dependencies of ResponseCache –

public static IServiceCollection AddApplicationServices(this IServiceCollection services)
{
    services.AddSingleton<IResponseCacheService, ResponseCacheService>();
    return services;
}

IResponseCacheService.cs –

public interface IResponseCacheService
{
    Task CacheResponseAsync(string cacheKey, object response, TimeSpan timeToLive);
    Task<string> GetCachedResponseAsync(string cacheKey);
}

and it’s implementation –

public class ResponseCacheService:IResponseCacheService
{
    private readonly IDatabase _database;

    public ResponseCacheService(IConnectionMultiplexer redis)
    {
        _database = redis.GetDatabase();
    }

    public async Task CacheResponseAsync(string cacheKey, object response, TimeSpan timeToLive)
    {
        if (response == null)
        {
            return;
        };
        var options = new JsonSerializerOptions
        {
            PropertyNamingPolicy = JsonNamingPolicy.CamelCase
        };

        var serialisedResponse = JsonSerializer.Serialize(response, options);

        await _database.StringSetAsync(cacheKey, serialisedResponse, timeToLive);

    }

    public async Task<string> GetCachedResponseAsync(string cacheKey)
    {
    ***exception here***    
    var cachedResponse = await _database.StringGetAsync(cacheKey);

        if (cachedResponse.IsNullOrEmpty)
        {
            return null;
        }
        return cachedResponse;

    }
}

So where’s the twist? What is this exception actually trying to convey? In all the code I posted, what exactly is causing the above exception? I am not really sure about the purpose of the ConnectionMultiplexer, I followed it from a tutorial. Even that tutorial didn’t provide a thorough explanation. How should I remove this exception and get my webAPI working? Need your kind assistance on this.

Thanks,

6

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật