Skip to content

Instantly share code, notes, and snippets.

@kristoff-it
Last active October 9, 2019 20:53
Show Gist options
  • Save kristoff-it/a26cffe1bc6b414a3868cd9d986b8d08 to your computer and use it in GitHub Desktop.
Save kristoff-it/a26cffe1bc6b414a3868cd9d986b8d08 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)
# This time we do a transaction
tr = pool.multi_exec()
tr.set("key", "hello")
# `execute` must be awaited, and be careful,
# awaiting the set command would deadlock the program
# as you would never be able to commit the transaction!
await tr.execute()
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