title: Flask redis server session: Error in save_session
body: <p>Folks:
  I am moving my Flask app with redis for session storage into docker containers. My app runs happily when redis is run locally. However, when running a docker-compose with a redis image, I see the following error. I get an identical error whether my redis container is running or stopped:</p>
  
  <pre><code>2017-04-02 03:36:09,861] ERROR in app: Exception on / [GET]
  web_1    | Traceback (most recent call last):
  web_1    |   File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
  web_1    |     response = self.full_dispatch_request()
  web_1    |   File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1643, in full_dispatch_request
  web_1    |     response = self.process_response(response)
  web_1    |   File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1864, in process_response
  web_1    |     self.save_session(ctx.session, response)
  web_1    |   File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 926, in save_session
  web_1    |     return self.session_interface.save_session(self, session, response)
  web_1    |   File "/usr/local/lib/python2.7/site-packages/flask_session/sessions.py", line 165, in save_session
  web_1    |     self.redis.setex(name=self.key_prefix + session.sid, value=val,
  web_1    | AttributeError: 'str' object has no attribute 'setex'
  </code></pre>
  
  <p>I have added the following configuration properties to my app for session config:</p>
  
  <pre><code>SESSION_TYPE = "redis"
  SESSION_REDIS = "redis:6379"
  </code></pre>
  
  <p>I don't think this is a <code>docker-compose</code> issue as my app is successfully able to connect to the MySQL instance, still, here is my <code>docker-compose.yml</code> file just in case it points to something:</p>
  
  <pre><code>version: "3"
  services:
    mysql:
      build:
        context: db/
    web:
      build:
        context: web/
      ports:
      - "10080:80"
      depends_on:
      - "mysql"
      - "redis"
    redis:
      image: "redis:alpine"
  </code></pre>