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.

taman
  • 237
  • 2
  • 9
  • could you post your django settings file (did you set `REDIS_HOST`)? – dm03514 Dec 08 '14 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", } } }` – taman Dec 08 '14 at 18:16
  • Are you running redis on your on ec2 instance, or using their (AWS's) elastic-cache redis? – E.J. Brennan Dec 08 '14 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? – Kevin Cherepski Dec 08 '14 at 20:02
  • Redis is being run using AWS's elastic-cache. – taman Dec 08 '14 at 21:04

2 Answers2

15

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.

taman
  • 237
  • 2
  • 9
  • 1
    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. – Jim Mar 28 '16 at 19:32
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/

E.J. Brennan
  • 45,870
  • 7
  • 88
  • 116
  • 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. – taman Dec 09 '14 at 13:17