1

I am connecting .NET core app to AWS ElastiCache Redis. enter image description here

The AWS Elasticache Redis is running and port 6329 is open on security group. The client code is using StackExchange.Redis:

           var redis = ConnectionMultiplexer.Connect("redis-1.xxxx.0001.use1.cache.amazonaws.com:6379");
           //var redis = ConnectionMultiplexer.Connect("localhost"); //working
           IDatabase db = redis.GetDatabase();

            string value = "abcdefg";
            db.StringSet("mykey", value);        

            string value2 = db.StringGet("mykey");
            Console.WriteLine(value2); // writes: "abcdefg"

            Console.ReadLine();

Exception is:

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

Added to ,abortConnect=false to the endpoint, I am able to connect.

Now the error is at StringSet

StackExchange.Redis.RedisConnectionException: 'No connection is available to service this operation: SET mykey; UnableToConnect ...

The .NET code is working fine with my local Redis service so looks like something incorrect with my AWS setup.

Successfully ssh to my EC2-instance and redis-cli to my AWS redis service: enter image description here

Any idea please?

NOTE: AWS Elasticache Redis is NOT available for public access as default.

8
  • Maybe try connecting to the server using redis-cli from your workstation? Commented Mar 14, 2020 at 8:26
  • successfully ssh into a ec2-instance and run redis-cli againt my aws redis service. But still failed from .net app (docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/…) Commented Mar 14, 2020 at 10:09
  • Just to be clear, you're getting this error when you deploy your code to the same EC2 instance? In that case, there shouldn't be any issues since the redis-cli can connect fine. Commented Mar 14, 2020 at 10:18
  • I am running .net code from my machine. Thought redis-1.xxxx.0001.use1.cache.amazonaws.com:6379 is public available via security group (TCP\6379 for All IPs)? Commented Mar 14, 2020 at 10:23
  • Try to connect to your redis server from your own machine then with redis-cli, not from the EC2. Commented Mar 14, 2020 at 10:25

2 Answers 2

0

Question: "...port 6329 is open on security group.." Dont you mean 6379?

Even that, i think i cn have an issue on the "default" subnet groups.

Does the VPC_Subnet (in that group) where the AWS ElastiCache Redis is, has a Routing Table with access to the Internet Gateway? If not, you need to attache the InternetGteway to the Route Table and than use that Route Table on the Subnet that you want.

It should be like the pick: Internet GW

Sign up to request clarification or add additional context in comments.

Comments

0

Had a similar issue trying to connect from an EC2 instance. My problem was that I had to set the SSL option to true:

 ConnectionMultiplexer.Connect(
                    Configuration.GetConnectionString("Redis"), o =>
                    {
                        o.AbortOnConnectFail = false;
                        o.ConnectRetry = 5;
                        o.Ssl = true;
                    }));

Otherwise I was getting error:

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.