Created
May 15, 2020 11:19
-
-
Save lucaspolo/28fe41f5fe085428a8bd52dd94bdb7f2 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 | |
import aioredis | |
async def create_registers(): | |
redis = await aioredis.create_redis_pool( | |
'redis://localhost' | |
) | |
for i in range(1_000_000): | |
await redis.sadd('reserved_codes', i) | |
async def get_codes(): | |
redis = await aioredis.create_redis_pool( | |
'redis://localhost' | |
) | |
codes = set() | |
for i in range(10_000): | |
code = await redis.spop('reserved_codes') | |
codes.add(code) | |
print(f'Size of codes {len(codes)}') | |
async def main(): | |
print('Inserting codes in Redis Set') | |
await create_registers() | |
coros = {get_codes() for i in range(100)} | |
print(f'Starting getting codes') | |
await asyncio.gather(*coros) | |
if __name__ == "__main__": | |
asyncio.run( | |
main() | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment