8

I've got a django project using django-redis 3.8.0 to connect to an aws instance of redis. However, I receive ConnectionError: Error 111 connecting to None:6379. Connection refused. when trying to connect. If I ssh into my ec2 and use redis-py from the shell, I am able to read and write from the cache just fine, so I don't believe it's a security policy issue.

5
  • could you post your django settings file (did you set REDIS_HOST)? Commented Dec 8, 2014 at 18:11
  • The only redis specific setting I have is: CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": "myawsredislocation:6379", 'KEY_PREFIX': 'projectname', "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", } } } Commented Dec 8, 2014 at 18:16
  • Are you running redis on your on ec2 instance, or using their (AWS's) elastic-cache redis? Commented Dec 8, 2014 at 19:56
  • You say if you ssh into your ec2 instance (I'm assuming this is also the instance running redis) you are able to connect to redis... this would imply a localhost connection and isn't even touching any AWS firewall security groups. Where is django running from? Commented Dec 8, 2014 at 20:02
  • Redis is being run using AWS's elastic-cache. Commented Dec 8, 2014 at 21:04

2 Answers 2

16

Ok, figured it out. What I needed to do was prefix my location with redis://. This is specific to the django-redis library and how it parses the location url. That explains why when I manually set up a StrictRedis connection using the python redis library I was able to connect.

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

1 Comment

For other users having this problem who have a non-AWS Redis server, I found that adding the "redis://" prefix to the LOCATION key wasn't sufficient. I also had to add my server's IP address to the 'bind' directive in /etc/redis/redis.conf. The file says Redis listens on all ports by default but I didn't find this to be the case. In fact, I could remove the 'redis' protocol prefix and it still worked so long as I was binding redis to my server's IP.
2

If you are running elastic-cache redis, you can't access it from outside AWS - that is why you are getting the error.

From AWS FAQ:

Please note that IP-range based access control is currently not enabled for Cache Clusters. All clients to a Cache Cluster must be within the EC2 network, and authorized via security groups as described above.

http://aws.amazon.com/elasticache/faqs/

1 Comment

I'm not accessing it from outside AWS, I'm accessing from an ec2 instance. And I'm able to access the cache from said instance using the redis-py library so I can verify that the security groups have been set up correctly.

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.