Skip to content

Instantly share code, notes, and snippets.

@kristoff-it
Created September 18, 2019 13:21
Show Gist options
  • Save kristoff-it/9789f05a6550b145165d5d6fc4d0e427 to your computer and use it in GitHub Desktop.
Save kristoff-it/9789f05a6550b145165d5d6fc4d0e427 to your computer and use it in GitHub Desktop.
import asyncio, aioredis
async def main():
pool = await aioredis.create_redis_pool('localhost',
db=0, password=None, ssl=False, minsize=4, maxsize=10, encoding='utf8')
# Assuming we're not the only ones using the pool
start_other_coroutines_that_use_redis(pool)
# We reserve a connection for a blocking operation
with await pool as conn:
items = await conn.xread(['stream'], latest_ids=['$'], timeout=0)
await process_items(items)
if __name__ == '__main__':
loop = asyncio.main_loop()
loop.run_until_complete(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment