title: aioredis + aiohttp proper usage of connection pooling
body: <p>I'm running the code below. I'm trying to use aioredis with aiohttp by creating a global connection pool object that I can use in the aiohttp view objects. However the load_redis function is erroring out. I'm not even sure if this is the right way to use aioredis in conjunction with aiohttp. </p>
  
  <pre><code>#!/usr/bin/env python
  
  import asyncio
  import uvloop
  from aiohttp import web
  from settings import SERVER_IP, SERVER_PORT, REDIS_HOST, REDIS_PORT
  import aiohttp_jinja2
  import jinja2
  import aioredis
  
  
  
  
  
  asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
  loop = asyncio.get_event_loop()
  app = web.Application()
  aiohttp_jinja2.setup(app,
      loader=jinja2.FileSystemLoader('templates'))
  
  REDIS_CONNECTION_POOL = None
  async def load_redis():
      global REDIS_CONNECTION_POOL
      REDIS_CONNECTION_POOL = await aioredis.create_pool(
          (REDIS_HOST, REDIS_PORT),
          minsize=5, maxsize=10,
          loop=loop)
      await REDIS_CONNECTION_POOL.execute('set', 'current_code', '00000')
  loop.run_until_complete(load_redis())
  
  
  #prevent import errors
  from routes import setup_routes
  setup_routes(app)
  web.run_app(app, host=SERVER_IP, port=SERVER_PORT)
  </code></pre>
  
  <p>This is the error message I'm seeing when I run this:</p>
  
  <pre><code>Traceback (most recent call last):
    File "server.py", line 29, in &lt;module&gt;
      loop.run_until_complete(load_redis())
    File "uvloop/loop.pyx", line 1203, in uvloop.loop.Loop.run_until_complete (uvloop/loop.c:25632)
    File "server.py", line 28, in load_redis
      await REDIS_CONNECTION_POOL.execute('set', 'current_code', '00000')
  AttributeError: 'RedisPool' object has no attribute 'execute'
  Task was destroyed but it is pending!
  task: &lt;Task pending coro=&lt;RedisPool._do_close() running at /Users/brian/.pyenv/versions/3.6.0/lib/python3.6/site-packages/aioredis/pool.py:117&gt; wait_for=&lt;Future pending cb=[&lt;TaskWakeupMethWrapper object at 0x10bb94b58&gt;()]&gt;&gt;
  </code></pre>