Can't connect to AWS ElastiCache Redis cluster in .NET 6 application

Viewed 33

I have created a .NET application and trying to connect to a AWS Redis cluster but I am receiving this exception:

It was not possible to connect to the redis server(s). UnableToConnect on *****.cache.amazonaws.com:6379/Interactive, Initializing/NotStarted, last: NONE, origin: BeginConnectAsync, outstanding: 0, last-read: 0s ago, last-write: 0s ago, keep-alive: 60s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 47s ago, v: 2.2.4.27433

Here is my code and the way I have configured the service.

public class DistributedCacheProvider : ICacheProvider
{
  private readonly IDistributedCache _distributedCache;

  public DistributedCacheProvider(IDistributedCache distributedCache)
  {
      _distributedCache = distributedCache;
  }
}

public async Task SetAsync<TKey, TValue>(TKey key, TValue value)
{ ... }

public async Task<TValue> GetAsync<TKey, TValue>(TKey key)
{ ... }

in startup.cs:

services.AddSingleton<ICacheProvider, DistributedCacheProvider>();
   
services.AddStackExchangeRedisCache(options =>
{
    options.Configuration = "*******.cache.amazonaws.com:6379";
    options.InstanceName = "cache-instance-name";
});

Is there something I am missing in the code or some other type of configuration that needs to be done from AWS?

0 Answers
Related