Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

talking to a remote redis server using redis-py (python wrapper over redis)

I have installed redis on an independent database server(ec2 instance). And it has been installed and configured properly. Now all that I want to do is from my webserver, I connect to it, and make changes to its key value store.

I have a python/django application running on heroku, and I am using PostgreSQL for everything else, I am using redis just to store some temporary variable in the KV sets.

Now, I install https://github.com/andymccurdy/redis-py on my localserver, and webserver.

To test the connection and check if things are working well, I try the following in my environment :

>>> pool = redis.ConnectionPool(host='MY_DBSERVER_IP_ADDRESS', port=6379, db=0)
>>> r = redis.Redis(connection_pool=pool)
>>> r.set('foo', 'bar')

this gives me an error - ConnectionError: Error 111 connecting 54.235.xxx.xxx:6379. Connection refused.

How do I connect? What am I missing?

like image 559
user1629366 Avatar asked May 14 '13 09:05

user1629366


People also ask

Can Redis handle multiple connections?

Redis can handle many connections, and by default, Redis has a maximum number of client connections set at 10,000 connections. You can set the maximum number of client connections you want the Redis server to accept by altering the maxclient from within the redis. conf file.

How do I know if Redis is connected in Python?

If you want to test redis connection once at startup, use the ping() command. The command ping() checks the connection and if invalid will raise an exception.


2 Answers

By default the config is set to only bind to 127.0.0.1 You just need to find your config (/etc/redis/redis.conf on Ubuntu) and comment out the bind 127.0.0.1 line.

like image 72
William K Avatar answered Oct 07 '22 15:10

William K


So what I ended up doing was, removing uncommenting bind 127.0.0.1 to bind 0.0.0.0

like image 30
user1629366 Avatar answered Oct 07 '22 15:10

user1629366