Created
September 18, 2019 13:21
-
-
Save kristoff-it/9789f05a6550b145165d5d6fc4d0e427 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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