Kacper Wikieł
Kacper Wikieł

Reputation: 260

How to connect to redis with dokku and flask?

I wanted to use redis with dokku and flask. First issue was installing current version of dokku, i am using latest version from repo now.

Second problem is showing in Flask debugger:

redis.exceptions.ConnectionError
ConnectionError: Error 111 connecting to None:6379. Connection refused.

I set redis url and port in Flask:

app.config['REDIS_URL'] = 'IP:32768'                                                                                         

-----> Checking status of Redis remote: Found image redis/landing remote: Checking status...stopped. remote: Launching redis/landing...COMMAND: docker run -v /home/dokku/.redis/volume-landing:/var/lib/redis -p 6379 -d redis/landing /bin/start_redis.sh -----> Setting config vars REDIS_URL: redis://IP:6379 REDIS_IP: IP REDIS_PORT: 6379

Any idea? REDIS_URL should be set in different way?

This code works ok in localhost: https://github.com/kwikiel/bounce (with ['REDIS_IP'] = '172.17.0.13' set to 127.0.0.1)

Problem appears when i try to connect with redis dokku.

Upvotes: 0

Views: 2031

Answers (1)

Kacper Wikieł
Kacper Wikieł

Reputation: 260

Steps to use redis with flask and dokku:

  1. Install redis plugin:

    cd /var/lib/dokku/plugins

    git clone https://github.com/ohardy/dokku-redis redis

    dokku plugins-install

  2. Link your redis container to application container

    dokku redis:create [name of app container]

You will receive info about environmental variables that you will have to set - for example:

   Host: 172.17.0.91
   Public port: 32771

Then set these settings in Flask (or other framework)

app.config['REDIS_URL'] =  'redis://172.17.0.91:6379' 
app.config['REDIS_IP'] = '172.17.0.91'                                      
app.config['REDIS_PORT'] = '6379'   

Complete example of redis database used with Flask app (A/B testing in Flask):

https://github.com/kwikiel/bounce

Upvotes: 1

Related Questions