title: Django & Redis: How do I properly use connection pooling?
body: <p>I have a Redis server which I query on almost every Django view for fetching some cached data. I've done some reading on some stackoverflow questions and learned that making a new Redis connection via <code>r = redis.StrictRedis(host='localhost', port=6379, db=0)</code> for every single web request is bad and that I should be using connection pooling.</p>
  
  <p>Here is the approach I came up with for connection pooling in Django:</p>
  
  <p>In <code>settings.py</code> so I can pull it up easily in any Django view as this is like a global variable:  </p>
  
  <pre><code># Redis Settings
  import redis
  REDIS_CONN_POOL_1 = redis.ConnectionPool(host='localhost', port=6379, db=0)
  </code></pre>
  
  <p>In some <code>views.py</code>:  </p>
  
  <pre><code>from django.conf import settings  
  REDIS_CONN_POOL_1 = settings.REDIS_POOL_1   
  r = redis.Redis(connection_pool=REDIS_CONN_POOL_1)
  r.get("foobar") # Whatever operation  
  </code></pre>
  
  <p>So, my question is: Is this the right way to do connection pooling in Django? Are there any better approaches you guys use for those have experienced a similar scenario like this? This is probably better than my old approach of opening and closing a new connection to redis on every request.</p>
  
  <p>EDIT: Gathered my understanding about why it's wrong to open a new connection on every request from this <a href="https://stackoverflow.com/questions/12967107/managing-connection-to-redis-from-python">stackoverflow question</a>.</p>