ankit
ankit

Reputation: 1529

Unable to connect to redis server deployed on Amazon ec2 on port 6379

I have set up a redis server on AWS ec2 instance following https://medium.com/@andrewcbass/install-redis-v3-2-on-aws-ec2-instance-93259d40a3ce

I am running a python script on another ec2 instance

import redis

try:
    conn = redis.Redis(host=<private ip address>,port=6379, db=1)
    user = {"Name":"Pradeep", "Company":"SCTL", "Address":"Mumbai", "Location":"RCP"}
    conn.hmset("pythonDict", user)
    conn.hgetall("pythonDict")
except Exception as e:
    print(e)

In the security groups of the redis server, i have allowed inbound traffic on port 6379

While running the above script, i am getting following error:

Error 111 connecting to 172.31.22.71:6379. Connection refused.

I have already tried changing the bind value in conf file, as suggested by a few answers to similar questions on stack overflow, but it didn't work

Upvotes: 1

Views: 2355

Answers (1)

Leo C
Leo C

Reputation: 22439

Assuming your other instance is within the same subnet as the Redis instance, my suggestion would be to review a couple of things:

  1. Make sure among your security group inbound rules, you have your Redis port set up for the subnet, like:

    6379 (REDIS)    172.31.16.0/20
    
  2. From within your Redis configuration (e.g. /etc/redis/redis.conf), in case this hasn't been done, either bind the server to the private IP (bind 172.31.22.71) or simply comment out any existing localhost binding, then restart Redis.

Upvotes: 1

Related Questions